首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在discord.js中定义args?

如何在discord.js中定义args?
EN

Stack Overflow用户
提问于 2019-04-10 01:38:40
回答 2查看 4.8K关注 0票数 0

本质上,我有一个命令,应该清除消息/泛洪聊天(这是为朋友,不要问),但我不断得到关于args未定义的错误,我该如何去解决这个问题?

背景:我一直在修补我的spaggehti代码(很多bot.on和if/else字符串),并且一直在尝试args,但是args没有定义,const也不能工作。

代码语言:javascript
复制
{
   if(message.content == '^immigrantalert')
   require ;amount = parseInt(args[0]);
   if (isNaN(amount)) {
        return message.reply('Immigrant purges need a god damn number after the command you twat');
   }
 else if (amount < 2 || amount > 100) {
  return message.reply('you need to input a number between 2 and 100 for Deportation you smack.');
  message.channel.bulkDelete(amount);
  message.reply('RULE BRITANNIA')
  message.reply('RULE BRITANNIA')
  message.reply('RULE BRITANNIA')
  message.reply('RULE BRITANNIA')
  message.reply('RULE BRITANNIA')
  message.reply('RULE BRITANNIA')
  message.reply('RULE BRITANNIA')
};

预期的输出是消息清除和泛洪,以在命令被说出来,但输出是一个崩溃在我的终端,这导致代码不工作。

EN

回答 2

Stack Overflow用户

发布于 2019-04-10 02:45:24

我想你想要这样的东西。

代码语言:javascript
复制
  let command = '^immigrantalert';
  if(message.content.includes(command)) { //look for command in message

     //check the end of the message for the amount
     let amount = parseInt(message.content.slice(command.length));

    if (isNaN(amount)) {
           return message.reply('Immigrant purges need a god damn number after the command you twat');
    } else if (amount < 2 || amount > 100) {
       message.reply('you need to input a number between 2 and 100 for Deportation you smack.');
      message.channel.bulkDelete(amount);
      message.reply('RULE BRITANNIA')
      message.reply('RULE BRITANNIA')
      message.reply('RULE BRITANNIA')
      message.reply('RULE BRITANNIA')
      message.reply('RULE BRITANNIA')
      message.reply('RULE BRITANNIA')
      message.reply('RULE BRITANNIA')
 }
}
票数 0
EN

Stack Overflow用户

发布于 2019-04-15 04:58:03

您需要将此代码添加到代码const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g); const command = args.shift().toLowerCase();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55598358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档