【问题标题】:How to do a 'Report Bug' command with discord.js如何使用 discord.js 执行“报告错误”命令
【发布时间】:2021-10-06 06:58:38
【问题描述】:

我一直在尝试报告“错误命令”。 到目前为止,这是我的代码:

bot.on('message', async (client, message, args) => {
    let parts = message.content.split(" ");

    if(parts[0].toLocaleLowerCase() == '!bugreport') {
        const owner = client.users.cache.get('567717280759283883');

        const query = args.join(" ");
        if(!query) return message.channel.send('Bitte schildere den Bug').then(m => m.delete({timeout: 5000}))
    
        const reportEmbed = new Discord.MessageEmbed()
        .setTitle('Fehlermeldung')
        .setThumbnail(message.guild.iconURL())
        .addField('Fehler:', query)
        .addField('Server:', message.guild.name, true)
        .setFooter(`Gesendet von ${message.author.tag}`, message.author.displayAvatarURL({dynamic: true}))
        .setTimestamp();
    
        owner.send(reportEmbed);
    }
});

错误代码总是说“内容”未定义,但我不明白

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    消息事件仅根据discord.js 文档传递接收到的消息。您的事件处理程序在开始时应该看起来更像这样:

    bot.on('message', async (message) => {
    

    请注意,这不会完全修复您的命令,因为您仍然会缺少 argsclient 参数。根据您使用它们的方式,我对从何处获取它们的最佳猜测是:

    const args = parts.splice(0,1); // gives array of everything after "!bugreport"
    const client = bot; // alternatively, replace client with bot in your code
    

    【讨论】:

      【解决方案2】:

      Client#message 事件允许 1 个参数,它是 Message 的一个实例。将您的代码更改为此

      bot.on('message', async (message) => {
      //code here
      })
      

      您可能对消息处理程序感到困惑,您可以在其中根据自己的喜好自定义函数。

      【讨论】:

        【解决方案3】:

        假设您的botClient,您似乎期望the message event 传递比实际更多的参数。虽然这表明您正在尝试从undefined 读取content,但并不是content 本身就是undefined

        【讨论】:

          猜你喜欢
          • 2021-06-07
          • 1970-01-01
          • 2021-06-02
          • 2021-02-27
          • 2021-05-21
          • 1970-01-01
          • 2019-03-05
          • 1970-01-01
          • 2021-05-29
          相关资源
          最近更新 更多