Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我如何让discord bot检查邮件内容并根据作者的不同回复不同的邮件?_Javascript_Discord.js - Fatal编程技术网

Javascript 我如何让discord bot检查邮件内容并根据作者的不同回复不同的邮件?

Javascript 我如何让discord bot检查邮件内容并根据作者的不同回复不同的邮件?,javascript,discord.js,Javascript,Discord.js,我如何让discord bot检查邮件内容并根据作者的不同回复不同的邮件? 这是到目前为止我的代码,我在教程中找到了它,但它不起作用。(由于某种原因,没有错误消息) client.on('message',函数(userID、channelID、message){ const thisWord=“我太酷了”; if(message.content.includes(thisWord)){ 如果(userID==''){ client.sendMessage({ 致:channelID, 信息:“

我如何让discord bot检查邮件内容并根据作者的不同回复不同的邮件? 这是到目前为止我的代码,我在教程中找到了它,但它不起作用。(由于某种原因,没有错误消息)

client.on('message',函数(userID、channelID、message){
const thisWord=“我太酷了”;
if(message.content.includes(thisWord)){
如果(userID==''){
client.sendMessage({
致:channelID,
信息:“同意”
})
}}
否则{
client.sendMessage({
致:channelID,
信息:“不同意”
})
}
})

首先,您必须使用更高版本的DJS。请更新至最新稳定版本v12.5.3。其次,事件只接受一个参数,而您给出了三个参数。第三,如果您想对不同的消息发送不同的回复,那么您需要处理消息内容。也就是说,按空间分割消息内容,然后处理它们。
可能会指导您使用用户输入命令。

这里的问题看起来您使用的是旧版本的DJS。使用最新的

这是discord.js v 12.5.3的正确用法

// the id should be like this '429493473259814923' :)
client.on('message', async message => {
    const thisWord = 'i\'m so cool';
    if (message.content.toLowerCase().includes(thisWord)) {
        if (message.author.id === 'ID') message.reply('disagreed');
        else message.reply('disagreed');
    }
});


我用
message.author.id
检查userID。请查看。您只会收到
消息
,因此需要使用此选项
// the id should be like this '429493473259814923' :)
client.on('message', async message => {
    const thisWord = 'i\'m so cool';
    if (message.content.toLowerCase().includes(thisWord)) {
        if (message.author.id === 'ID') message.reply('disagreed');
        else message.reply('disagreed');
    }
});