Get Discord bot to join when a user joins then leaves after sound is played
I'm trying to get the Discord bot to join when a specific user joins. The bot shows online in the Discord server but isn't joining when I join. Is there a way the username has to be formatted or am I missing something?
I thought it was the username missing the # tag for the username but that didn't produce any results.
console.log('On');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.GuildVoiceStates
]
});
client.on('voiceStateUpdate', (oldState, newState) => {
/开发者_StackOverflow中文版/ 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');
client.on('voiceStateUpdate', (oldState, newState) => {
// Check if the user who joined is the specific user we want
if (newState.member.id === 'USE_YOUR_ID_PLS') {
// Check if the user joined a voice channel
if (newState.channel) {
// Join the voice channel and play the specific sound
newState.channel.join()
.then(connection => {
// Replace 'song.mp3' with the path to the audio file you want to play
const dispatcher = connection.play('C:\Users\storr\Music\botsounds\song.mp3');
// Leave the voice channel after the sound is played
dispatcher.on('finish', () => {
newState.channel.leave();
});
})
.catch(console.error);
}
}
});
do the same thing when u leave , just add an else , I was too lazy to write it again
精彩评论