所以我正在学习discord.Js,我试图找出为什么我的message.reply功能不起作用。我为机器人创建了一个事件来监听消息,当发送内容为“hello”的消息时,它应该回复“hello buddy”,代码如下:
require('dotenv').config()
const discord = require('discord.js')
const client = new discord.Client({
intents: []
});
client.login(process.env.TOKEN);
client.on('ready', () => {
console.log(`${client.user.tag} has logged in`);
});
client.on('message', function(message){
if(message.content === 'hello') {
message.reply('hello buddy')
}
});
discord 中的机器人拥有在我测试的服务器中发送消息所需的所有权限。
最佳答案
您的机器人未检测到消息。您需要 GUILDS
和 GUILD_MESSAGES
意图
const client = new discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES"]
})
此外,message
事件已被弃用。使用 messageCreate
代替
client.on('messageCreate', (message) => {
if(message.content === 'hello') {
message.reply('hello buddy')
}
})
请注意,我使用了箭头函数。它们是更清晰的语法,您应该在回调中使用它们
关于javascript - 为什么我的 "message.reply"不起作用(Discord.JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70117564/