我正在尝试让Discord机器人在特定用户加入时加入。机器人在Discord服务器上显示在线,但在我加入时它并没有加入。是否必须格式化用户名,或者我遗漏了什么?
我以为是用户名缺少#标记,但没有产生任何结果。
console.log('On');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.GuildVoiceStates
]
});
client.on('voiceStateUpdate', (oldState, newState) => {
// Check if the user who joined is the specific user we want
if (newState.member.id === 'SteveT') {
// Check if the user joined a voice channel
if (newState.channel) {
// Play the specific sound
newState.channel.join().then(connection => {
const dispatcher = connection.play('C:\Users\storr\Music\botsounds');
dispatcher.on('finish', () => {
// Leave the voice channel after the sound is played
newState.channel.leave();
});
});
}
}
});
client.login('insertbotkey');
1条答案
按热度按时间q9yhzks01#
用途:
离开时做同样的事情;再加一个else就行了。2我懒得再写了。