.setSelfDeaf ()를 사용할 때 어떻게이 ReferenceError를 수정할 수 있습니까?

Ipho3nix

내 코드에서 .setSelfDeaf ()를 사용하려고하는데 알아낼 수 없었습니다. 내가 시도한 모든 방법은 실행될 때 봇을 충돌시키는 결과를 낳았습니다.

누군가가 그것을 사용하도록 도울 수 있습니까? 내가 원하는 것은 봇이 음성 채널에 참여할 때마다 자신을 방어하는 것입니다.

편집 : 내가 받고있는 오류와 요청시 업데이트 된 코드를 추가했습니다.

내가 얻는 오류 :

2021-03-04T06:25:06.238627+00:00 app[worker.1]: /app/code.js:53
2021-03-04T06:25:06.238628+00:00 app[worker.1]:     connection.voice.setSelfDeaf(true);
2021-03-04T06:25:06.238629+00:00 app[worker.1]:     ^
2021-03-04T06:25:06.238629+00:00 app[worker.1]: 
2021-03-04T06:25:06.238629+00:00 app[worker.1]: ReferenceError: connection is not defined
2021-03-04T06:25:06.238630+00:00 app[worker.1]:     at Client.<anonymous> (/app/code.js:53:5)
2021-03-04T06:25:06.238630+00:00 app[worker.1]:     at Client.emit (events.js:327:22)
2021-03-04T06:25:06.238631+00:00 app[worker.1]:     at VoiceStateUpdate.handle (/app/node_modules/discord.js/src/client/actions/VoiceStateUpdate.js:40:14)
2021-03-04T06:25:06.238632+00:00 app[worker.1]:     at Object.module.exports [as VOICE_STATE_UPDATE] (/app/node_modules/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js:4:35)
2021-03-04T06:25:06.238632+00:00 app[worker.1]:     at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
2021-03-04T06:25:06.238633+00:00 app[worker.1]:     at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
2021-03-04T06:25:06.238633+00:00 app[worker.1]:     at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
2021-03-04T06:25:06.238634+00:00 app[worker.1]:     at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:132:16)
2021-03-04T06:25:06.238634+00:00 app[worker.1]:     at WebSocket.emit (events.js:315:20)
2021-03-04T06:25:06.238634+00:00 app[worker.1]:     at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:825:20)
2021-03-04T06:25:06.279643+00:00 heroku[worker.1]: Process exited with status 1
2021-03-04T06:25:06.340294+00:00 heroku[worker.1]: State changed from up to crashed

업데이트 된 코드 :

const Discord = require('discord.js'),
    DisTube = require('distube'),
    client = new Discord.Client(),
    config = {
        prefix: "em!",
        token: process.env.TOKEN || "[insert discord bot token]"
    };


const distube = new DisTube(client, { searchSongs: true, emitNewSongOnly: true });

client.on('ready', () => {
    console.log(`e-Music is up and running`);
    client.user.setActivity(`em!play`)
});

client.on("message", async (message) => {
    if (message.author.bot) return;
    if (!message.content.startsWith(config.prefix)) return;
    const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
    const command = args.shift();

    if (command == "play")
        distube.play(message, args.join(" "));

    if (["repeat", "loop"].includes(command))
        distube.setRepeatMode(message, parseInt(args[0]));

    if (command == "stop") {
        distube.stop(message);
        message.channel.send("Stopped the music!");
    }

    if (command == "skip")
        distube.skip(message);

    if (command == "queue") {
        let queue = distube.getQueue(message);
        message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
            `**${id + 1}**. ${song.name} - \`${song.formattedDuration}\``
        ).slice(0, 10).join("\n"));
    }

    if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
        let filter = distube.setFilter(message, command);
        message.channel.send("Current queue filter: " + (filter || "Off"));
    }
});

client.on("voiceStateUpdate", (oldVoiceState, newVoiceState) => {
    if (newVoiceState.id == client.user.id) {
        connection.voice.setSelfDeaf(true);
    };
});

const status = (queue) => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filter || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode == 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;

distube
    .on("playSong", (message, queue, song) => message.channel.send(
        `Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}\n${status(queue)}`
    ))
    .on("addSong", (message, queue, song) => message.channel.send(
        `Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`
    ))
    .on("playList", (message, queue, playlist, song) => message.channel.send(
        `Play \`${playlist.name}\` playlist (${playlist.songs.length} songs).\nRequested by: ${song.user}\nNow playing \`${song.name}\` - \`${song.formattedDuration}\`\n${status(queue)}`
    ))
    .on("addList", (message, queue, playlist) => message.channel.send(
        `Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to queue\n${status(queue)}`
    ))

    .on("searchResult", (message, result) => {
        let i = 0;
        message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`);
    })

    .on("searchCancel", (message) => message.channel.send(`Searching canceled`))
    .on("error", (message, e) => {
        console.error(e)
        message.channel.send("An error encountered: " + e);
    });

client.login(config.token);
벚나무

오류를 읽으면 ReferenceError: connection is not defined무엇이 잘못되었는지 알려줍니다. connection다음 코드에서는 변수가 아닙니다.

client.on("voiceStateUpdate", (oldVoiceState, newVoiceState) => {
    if (newVoiceState.id == client.user.id) {
        connection.voice.setSelfDeaf(true);
    };
});

connection에 재산 newVoiceState이 당신이이 시나리오에서 원하는 것은 아니지만 생각은. 다음에서 .setSelfDeaf방법 을 사용하고 싶을 것 입니다 VoiceState.

client.on("voiceStateUpdate", (oldVoiceState, newVoiceState) => {
    if (newVoiceState.id == client.user.id) {
       newVoiceState.setSelfDeaf(true);
    };
});

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

MassTransit SQS를 사용할 때 MessageGroupId를 어떻게 설정할 수 있습니까?

분류에서Dev

MassTransit SQS를 사용할 때 MessageGroupId를 어떻게 설정할 수 있습니까?

분류에서Dev

Meson을 사용할 때 라이브러리 경로를 어떻게 지정할 수 있습니까?

분류에서Dev

열 데이터를 살펴볼 때 어떻게 사용할 수 있습니까?

분류에서Dev

특정보기를 선택할 때 수명주기 방법을 어떻게 사용할 수 있습니까?

분류에서Dev

tempus-fugit 및 junit을 사용할 때 스레드 수를 어떻게 정의 할 수 있습니까?

분류에서Dev

zip () 함수를 사용할 때 다음 오류를 어떻게 수정할 수 있습니까? TypeError : '목록'개체를 호출 할 수 없습니다.

분류에서Dev

VS Code를 사용할 때 TLA + 구성 파일에서 CONSTANTS를 어떻게 설정할 수 있습니까?

분류에서Dev

XDomainRequest를 사용할 때 어떻게 헤더를 얻을 수 있습니까?

분류에서Dev

Unity 2D를 사용할 때 창 이동 키를 어떻게 변경할 수 있습니까?

분류에서Dev

django / javascript를 사용할 때이 예기치 않은 토큰 오류를 어떻게 피할 수 있습니까?

분류에서Dev

Unity 2D를 사용할 때 창 이동 키를 어떻게 변경할 수 있습니까?

분류에서Dev

DependencyProperty를 사용할 때 상속 된 값과 할당 된 값의 차이를 어떻게 알 수 있습니까?

분류에서Dev

키보드 단축키를 사용할 때 Geany 날짜 형식을 어떻게 조정할 수 있습니까?

분류에서Dev

manage.py를 실행할 때 이러한 오류를 어떻게 수정할 수 있습니까?

분류에서Dev

최적화 도구를 사용할 때 입력 인수를 어떻게 사용할 수 있습니까?

분류에서Dev

Java 7이 설치되어있을 때 Mavericks에서 Gephi를 어떻게 사용할 수 있습니까?

분류에서Dev

IF 문의 정보를 어떻게 사용할 수 있습니까?

분류에서Dev

UseExternalSignInCookie를 어떻게 사용자 정의 할 수 있습니까?

분류에서Dev

이 API를 어떻게 사용할 수 있습니까?

분류에서Dev

uigetfile을 사용할 때 어떻게 오류를 잡을 수 있습니까? [MATLAB]

분류에서Dev

이 SliverPersistentHeader Renderflexerror를 어떻게 수정할 수 있습니까?

분류에서Dev

이 JavaScript를 어떻게 수정할 수 있습니까?

분류에서Dev

이 쿼리를 어떻게 수정할 수 있습니까?-MySQL

분류에서Dev

이 오류를 어떻게 수정할 수 있습니까?

분류에서Dev

이 코드를 어떻게 수정할 수 있습니까?

분류에서Dev

C #에서 사용자 지정 직렬화를 사용할 때 XML 요소의 이름을 어떻게 제어 할 수 있습니까?

분류에서Dev

Python의 requests.post 함수를 사용하여 동적 HTML을 웹 스크래핑 할 때 "페이지 번호"를 어떻게 지정할 수 있습니까?

분류에서Dev

keras 라이브러리를 사용하여 RNN을 훈련 할 때 계속 발생하는 차원 오류를 어떻게 수정할 수 있습니까?

Related 관련 기사

  1. 1

    MassTransit SQS를 사용할 때 MessageGroupId를 어떻게 설정할 수 있습니까?

  2. 2

    MassTransit SQS를 사용할 때 MessageGroupId를 어떻게 설정할 수 있습니까?

  3. 3

    Meson을 사용할 때 라이브러리 경로를 어떻게 지정할 수 있습니까?

  4. 4

    열 데이터를 살펴볼 때 어떻게 사용할 수 있습니까?

  5. 5

    특정보기를 선택할 때 수명주기 방법을 어떻게 사용할 수 있습니까?

  6. 6

    tempus-fugit 및 junit을 사용할 때 스레드 수를 어떻게 정의 할 수 있습니까?

  7. 7

    zip () 함수를 사용할 때 다음 오류를 어떻게 수정할 수 있습니까? TypeError : '목록'개체를 호출 할 수 없습니다.

  8. 8

    VS Code를 사용할 때 TLA + 구성 파일에서 CONSTANTS를 어떻게 설정할 수 있습니까?

  9. 9

    XDomainRequest를 사용할 때 어떻게 헤더를 얻을 수 있습니까?

  10. 10

    Unity 2D를 사용할 때 창 이동 키를 어떻게 변경할 수 있습니까?

  11. 11

    django / javascript를 사용할 때이 예기치 않은 토큰 오류를 어떻게 피할 수 있습니까?

  12. 12

    Unity 2D를 사용할 때 창 이동 키를 어떻게 변경할 수 있습니까?

  13. 13

    DependencyProperty를 사용할 때 상속 된 값과 할당 된 값의 차이를 어떻게 알 수 있습니까?

  14. 14

    키보드 단축키를 사용할 때 Geany 날짜 형식을 어떻게 조정할 수 있습니까?

  15. 15

    manage.py를 실행할 때 이러한 오류를 어떻게 수정할 수 있습니까?

  16. 16

    최적화 도구를 사용할 때 입력 인수를 어떻게 사용할 수 있습니까?

  17. 17

    Java 7이 설치되어있을 때 Mavericks에서 Gephi를 어떻게 사용할 수 있습니까?

  18. 18

    IF 문의 정보를 어떻게 사용할 수 있습니까?

  19. 19

    UseExternalSignInCookie를 어떻게 사용자 정의 할 수 있습니까?

  20. 20

    이 API를 어떻게 사용할 수 있습니까?

  21. 21

    uigetfile을 사용할 때 어떻게 오류를 잡을 수 있습니까? [MATLAB]

  22. 22

    이 SliverPersistentHeader Renderflexerror를 어떻게 수정할 수 있습니까?

  23. 23

    이 JavaScript를 어떻게 수정할 수 있습니까?

  24. 24

    이 쿼리를 어떻게 수정할 수 있습니까?-MySQL

  25. 25

    이 오류를 어떻게 수정할 수 있습니까?

  26. 26

    이 코드를 어떻게 수정할 수 있습니까?

  27. 27

    C #에서 사용자 지정 직렬화를 사용할 때 XML 요소의 이름을 어떻게 제어 할 수 있습니까?

  28. 28

    Python의 requests.post 함수를 사용하여 동적 HTML을 웹 스크래핑 할 때 "페이지 번호"를 어떻게 지정할 수 있습니까?

  29. 29

    keras 라이브러리를 사용하여 RNN을 훈련 할 때 계속 발생하는 차원 오류를 어떻게 수정할 수 있습니까?

뜨겁다태그

보관