【问题标题】:Attempt to create a command with 2 arguments尝试使用 2 个参数创建命令
【发布时间】:2021-06-25 00:37:56
【问题描述】:

我正在尝试编写一个命令,以便输入两个名称,这些名称被标识为 Query1 和 Query2,但是,我不知道该怎么做,有人可以帮助我吗?

const {MessageEmbed} = require('discord.js');

module.exports ={
    name : 'battle',
    aliases: ['batalha'],
    run : async(client, message) => {
        
        await message.delete();

        const query1 = args[0].join(" ");
        if(!query1) return message.reply('Adicione o primeiro nome!');

        const query2 = args[1].join(" ");
        if(!query2) return message.reply('Adicione o segundo nome!')

        var embed = new MessageEmbed()
        .setColor('RANDOM')
        .setAuthor('BATALHA DE FOTOS', client.user.avatarURL)
        .setDescription(`Marque o emoji de acordo com o seu voto: \n\n ${query1}: ???? \n${query2}: ????`)
        .setFooter(message.author.username, message.author.displayAvatarURL)
        .setTimestamp()
        .setThumbnail('https://i.imgur.com/1oHJJZQ.png')

        const msg = await message.channel.send(embed)
        await msg.react('????')
        await msg.react('????')
        
    }
}

错误

(node:864) UnhandledPromiseRejectionWarning: ReferenceError: args is not defined
    at Object.run (C:\Users\Pc\Desktop\RemakeGANGBOT\commands\info\battle.js:10:24)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:864) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:864) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

【问题讨论】:

  • 你遇到了什么错误(如果有的话)?
  • (node:10872) UnhandledPromiseRejectionWarning: ReferenceError: args is not defined at Object.run
  • 好吧,你还没有定义args,args 应该从哪里来?

标签: javascript node.js discord discord.js bots


【解决方案1】:

您似乎没有定义args。您可以在为您的命令运行任何代码之前定义它,方法是:

const args = message.content.trim().split(/ +/g);

【讨论】:

    猜你喜欢
    • 2019-07-04
    • 2021-06-24
    • 1970-01-01
    • 2018-01-23
    • 2014-07-25
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    相关资源
    最近更新 更多