每次我在不和谐的服务器中发送一条消息时,我的机器人垃圾邮件就会自动发送并ping通。
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'Faketoken';
bot.on('ready', () =>{
console.log('This bot is online!');
})
bot.on('message', msg=>{
if(msg.content = "hello"){
msg.reply('Hello!');
}
})
bot.login(token);
我认为问题出在bot.on('message',
答案 0 :(得分:2)
欢迎使用堆栈溢出!
所以首先要解决您的问题:您需要以下简单代码:if(message.author.bot) return;
事件开始时的message
。 为什么?好吧,机器人是响应本身。
它看到您的消息,发送回复。看到它自己的响应,并假设它是一条新消息。并发送另一个响应。一遍又一遍。
该行检查看到的消息是否来自机器人,如果是,则:什么都不做
第二个问题就在这里:if(msg.content = "hello")
这是设置 msg.content
为“你好”。 不检查是否与“ hello”匹配替换为:if(msg.content === "hello")