首页 > 解决方案 > 带有 Javascript 的 Discordbot 没有反应

问题描述

我目前正在学习使用 node.js 编写 discordbots。出于某种原因,机器人会上线,但不会对我编码的命令做出反应。为了测试原因,我什至从教程中获取了解决方案,但仍然是同样的问题。有人知道解决方案吗?

const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
    console.log('BOT ist online');
});

client.on('Message', (message) => {
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        message.channel.send('pong!');}
    else if(command == 'youtube'){
        message.channel.send('TEST');}
    });
client.login('Here goes the token');

标签: javascriptnode.jsdiscord

解决方案


这是一个小修复,所以如果可以的话,我会发表评论,但我还不能。

你在哪里:

client.on('Message', …)

它应该是这样的消息上的小写“m”:

client.on('message', msg => {
  if (msg.content === 'ping') {
     msg.reply('Pong!');
  }
});

推荐阅读