我如何获取我的不和谐bot所在的频道的频道ID和消息作者的频道ID

时间:2020-08-18 07:07:38

标签: javascript discord discord.js

我正在尝试发出不一致的bot离开命令,但我找不到要获得该bot的通道ID以及发送消息的用户进行比较以确保它们相同的用户

Crashbot.on('message', async message =>{

    //creates an array called args and removes the first amount of charactors equal to the length of the prefix variable
    let args = message.content.substring(PREFIX.length).split(" ");

    //the switch equals true if the first word after the prefix is "leave"
    switch (args[0]) {
        case 'leave':
    
        //if the message author is not in the same voice channel as the bot the bot replies and tells them that that have to be in the same channel to use that command
        if (message.member.voice.channel.id != Crashbot.voice.channel.id) {
            message.reply("You must be in the same channel as me to use this command");
        return;
        }

    //if the message author is in the same voice channel as the bot it leaves the channel it is in
    if (message.member.voice.channel.id === Crashbot.voice.channel.id) {
        const connection = await message.member.voice.channel.leave()
            message.channel.send("Successfully left the voice channel");
    }
    break;
}
});

1 个答案:

答案 0 :(得分:0)

看看Discord.js文档here

您可以使用self来获取语音连接的集合。您可以使用它来检查用户所在的频道ID是否与连接中的任何频道匹配。