我想制作一个discord bot,该机器人将在人们进入语音频道时更改其昵称,并在离开该频道后将其改回。我对javascript毫无头绪,因此需要帮助。
不适用
n / a
n / a
答案 0 :(得分:0)
我不知道您使用的是哪个库,因为您未指定该库,但是假设“ Discord”是discord.js,这是通过voiceStateUpdate事件在discord.js中实现的方法“客户”是您的Discord.Client:
var voiceNames = new Discord.Collection(); // we will store names here
client.on('voiceStateUpdate', (oldMember, newMember) => {
if (NewMember.voiceChannel) { // if they are in a voice channel
voiceNames.set(oldMember.user.id, oldMember.displayname); // add an Item/modify the previous one in our list of names to reset them later
NewMember.setNickname("New Nickname");
} else {
NewMember.setNickname(voiceNames.get(oldMember.user.id)); // set it back after they left
}
})