I want to make the bot detect when a user is talking. in the discord documentation I saw i needed to use the event guildMemberSpeaking
. This is the code:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Talkover is online!');
})
// Joins the voice channel with every tekst
client.on('message', async message => {
// Join the same voice channel of the author of the message
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
}
});
client.on('guildMemberSpeaking', (member, speaking) => {
if (speaking) {
console.log('speaking');
} else {
console.log('notspeaking');
}
});
for some reason message works but guildmemberspeaking not. I don't know what I'm doing wrong.
You have to use an async listener my friend
client.on('guildMemberSpeaking', async (member, speaking) => {
if (speaking) {
console.log('speaking');
} else {
console.log('notspeaking');
}
});
Just add async before your parameters and you're done.