【问题标题】:How come my "message.reply" is not working (Discord.JS)为什么我的“message.reply”不起作用(Discord.JS)
【发布时间】:2022-01-04 02:39:44
【问题描述】:

所以我正在学习 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 中的机器人拥有在我正在测试它的服务器中发送消息所需的所有权限。

【问题讨论】:

  • 事件是否触发?如果没有,可能是因为它已被弃用。文档建议改用messageCreate 事件。

标签: javascript discord.js


【解决方案1】:

您的机器人未检测到消息。你需要GUILDSGUILD_MESSAGES 意图

const client = new discord.Client({
    intents: ["GUILDS", "GUILD_MESSAGES"]
})

此外,message 事件已被弃用。请改用messageCreate

client.on('messageCreate', (message) => {
    if(message.content === 'hello') {
        message.reply('hello buddy')
    }
})

请注意,我使用了箭头函数。它们是更简洁的语法,你应该在回调中使用它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-15
    • 2021-12-06
    • 2020-11-22
    • 1970-01-01
    • 2022-08-17
    • 2022-01-02
    • 2022-07-31
    • 2015-09-25
    相关资源
    最近更新 更多