【发布时间】:2021-02-28 01:39:06
【问题描述】:
已经在 stackoverflow 上查找了所有问题,但没有任何效果。 如果有人加入特定语音频道,我希望我的机器人发送消息。
client.on('voiceStateUpdate', (oldMember, newMember) => {
// Here I'm storing the IDs of their voice channels, if available
const oldChannel = oldMember.voiceChannel ? oldMember.voiceChannel.id : null;
const newChannel = newMember.voiceChannel ? newMember.voiceChannel.id : null;
if (oldChannel == newChannel) return; // If there has been no change, exit
// Here I'm getting the client's channel (client.voiceChannel does not exist)
const clientMember = oldMember.guild.member(client.user),
clientChannel = clientMember ? clientMember.voiceChannel.id : null;
// Here I'm getting the channel, just replace VVV this VVV with the channel's ID
const textChannel = oldMember.guild.channels.get('765520462439645191');
if (!textChannel) throw new Error("That channel does not exist.");
// Here I don't need to check if they're the same, since it would've exit before
if (newChannel == clientChannel) {
// console.log("A user joined.");
textChannel.send(`${newMember} has joined the voice channel.`);
} else if (oldChannel == clientChannel) {
// console.log("A user left.");
textChannel.send(`${newMember} has left the voice channel.`);
}
不起作用。没有错误,但它不起作用。请帮忙
【问题讨论】:
标签: discord.js