Discord BOT,guildMemberSpeaking 事件不起作用

Discord BOT, guildMemberSpeaking event is not working

我想让机器人检测用户何时说话。在 discord 文档中,我看到我需要使用事件 guildMemberSpeaking。这是代码:

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');
    }

});

出于某种原因,消息有效但公会成员不说话。我不知道我做错了什么。

你必须使用异步侦听器我的朋友

client.on('guildMemberSpeaking', async (member, speaking) => {
    if (speaking) {
        console.log('speaking');
    } else {
        console.log('notspeaking');
    }
});

只需在参数前添加 async 即可。