discord bot 将某人转移到 afk 频道

discord bot moving someone to afk channel

好的,所以我希望我的 discord 机器人能够让人们在耳聋后挂机。问题是我不确定如何让机器人将它们移动到 afk 频道。它检测到我何时耳聋但在尝试执行命令时出现错误。任何帮助将不胜感激 <3

错误:

TypeError: newState.member.setVoiceChannel is not a function

代码:

const Discord = require("discord.js");

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILD_MEMBERS", "GUILD_PRESENCES"] });



client.on("voiceStateUpdate", (oldState, newState) =>
{

    if (newState.selfDeaf)
    {
        console.log('User has deafened');
        newState.member.setVoiceChannel("afkChannelId");
    }
});



client.once('ready', () => {
    console.log('Discord bot is now online!')
    
    });

那是因为 newState.member 是类型 GuildMember 并且没有 setVoiceChannel() 函数。

相反,您必须访问 voice property (newState.member.voice) and here you can use the setChannel() 函数。


TLDR

而不是

newState.member.setVoiceChannel("afkChannelId");

使用这个:

newState.member.voice.setChannel("channel ID", <reason>);
                                                  ^
                                               optional