消息未定义discord.js chatbot

时间:2020-05-12 07:38:00

标签: javascript discord discord.js chatbot

所以我试图让我的机器人正常工作,但是代码显示消息未定义。我已经尝试了所有我想做的事情:

const Discord = require('discord.js');
const client = new Discord.Client();

client.once('ready', () => {
    console.log('ready!');
});

if (message.content === '!ping') {
    message.channel.send('Pong.');
}

if (command === "!hug") {
    let user = message.mentions.users.first();
    message.channel.send("You have been hugged " + user);
}

client.login('my-bot-token');

1 个答案:

答案 0 :(得分:0)

我认为您忘记为消息添加事件侦听器。

const Discord = require('discord.js');
const client = new Discord.Client();

client.once('ready', () => {
    console.log('ready!');
});

client.on("message", (message) => {
    if (message.content === '!ping') {
        message.channel.send('Pong.');
    }

    if (command === "!hug") {
        let user = message.mentions.users.first();
        message.channel.send("You have been hugged " + user);
    }
}

client.login('my-bot-token');