javascript - 尝试使用 2 个参数创建命令
问题描述
我正在尝试创建一个命令,以便输入两个名称,这些名称被标识为 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.
解决方案
看起来你没有定义args
. 您可以在为您的命令运行任何代码之前定义它,方法是:
const args = message.content.trim().split(/ +/g);
推荐阅读
- java - java.util.concurrent.ExecutionException:java.lang.Error:无效的内存访问
- python-3.x - 占位符的自动格式化
- php - 插入到 mysql 数据库准备状态
- java - Java:尝试获取 HTML 元素的值
- c# - 通过索引号 wpf mvvm 在 listview itemsource 中搜索值
- angular - 尝试安装 @ngx-progressbar/core 时未满足的依赖项
- php - 基于 Wordpress 中活动类别的当前帖子的 PHP 滑块
- javascript - 计算 Qualtrics 中的 TAB 击键
- javascript - HTML 表单提交按钮刷新页面
- java - Java void 作为带参数的 Runnable