当有人加入特定频道时发送消息 - Discord Bot
Posted
技术标签:
【中文标题】当有人加入特定频道时发送消息 - Discord Bot【英文标题】:Send message when someone joins to the specific channel - Discord Bot 【发布时间】:2021-08-18 22:31:03 【问题描述】:我制作了一个 Discord 机器人,用于在有人加入特定频道时发送消息,但它也会在用户将麦克风静音时发送消息。怎么了?
你可以在下面找到我当前的代码:
client.on('voiceStateUpdate', (oldMember, newMember) =>
let newUserChannel = newMember.channelID;
let oldUserChannel = oldMember.channelID;
const channel2 = client.channels.cache.get('channelid here');
if(newUserChannel === "channelid here")
// User Joins a voice channel
channel2.send("message");
);
【问题讨论】:
【参考方案1】:您还应该检查频道是否发生变化,因此请检查newMember.channelID
与oldMember.channelID
是否不同:
client.on('voiceStateUpdate', (oldMember, newMember) =>
let newUserChannel = newMember.channelID;
let oldUserChannel = oldMember.channelID;
const channel2 = client.channels.cache.get('channelid here');
if (
newUserChannel !== oldUserChannel &&
newUserChannel === 'channelid here'
)
// User Joins a voice channel
channel2.send('message');
);
【讨论】:
以上是关于当有人加入特定频道时发送消息 - Discord Bot的主要内容,如果未能解决你的问题,请参考以下文章