【问题标题】:My Discord bot ist not responding (javascript) [closed]我的 Discord 机器人没有响应(javascript)[关闭]
【发布时间】:2021-02-01 02:42:09
【问题描述】:

所以当我使用 node.js 启动我自己的 Discord Bot 时,我正在尝试编写它。确实可以,但是当我输入 *ping 时,它没有应有的响应

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


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

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

    const args = message.content.slice(prefix.lenght).split(" ");
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        message.channel.send('pong!');
    }
});

哪里出错了?

【问题讨论】:

  • 如果您尝试记录argscommand,您会得到什么?
  • console.log(args)const args 下,与command (console.log(command)) 相同。检查控制台中的输出
  • 你也可以尝试登录message
  • 您将length 拼错为lenght
  • const args...这行有错字:prefix.lenght应该是prefix.length

标签: javascript discord.js


【解决方案1】:

问题是您将length 拼写为lenght

这可能会导致您的控制台出错。下次也请上传错误。

另外,既然您是从 discord.js 指南中复制代码,为什么不先检查一下呢? ?

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 2022-10-24
    • 1970-01-01
    • 2023-02-10
    • 2022-12-15
    • 2021-03-11
    • 2022-11-27
    • 1970-01-01
    相关资源
    最近更新 更多