【问题标题】:How to require from the user entering a second input to a Discord Bot?如何要求用户向 Discord Bot 输入第二个输入?
【发布时间】:2020-10-29 03:40:12
【问题描述】:

我正在尝试编写一个命令,该命令要求用户在初始输入后输入另一个输入。我尝试在包含命令模块的文件中创建客户端连接。

但是,我已经尝试和研究了没有结果,当我输入第二个输入时,机器人没有响应。

我尝试将主要参数传递给命令,以查看机器人是否可以接收另一个输入,但以评估第一个输入结束。

这是我第一次尝试创建代码的示例:

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

ule.exports = {
 name: 'command',
 description: 'A test command',
 execute(message, args){
     if(args == '1'){
         message.channel.send('Enter another input');
         client.on('message', message =>{
             if(!message.content.length || message.author.bot) return;
             const args = message.content.slice().split();
             if(args == '2'){
                 message.channel.send('Done!');
             }
         });
     }
 }
}

我曾想过在“client.on”函数中更改“message”参数的名称,但得到了相同的结果,我不确定它的范围是否仅在函数内部而不仅仅是传递的来自“执行”函数的参数

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

您要么创建awaitMessages

     if(!args[0]) return
     if(!args[1])
     {
        message.channel.send('Enter another input').then(m => {
            const m = await msg.channel.awaitMessages((mes) => mes.author.id == message.author.id, { max: 1, time: 50000, errors: ['time'] }).catch(err => console.log(err))
            args[1] = m.first();
        })  
     }

如果没有第二个参数,你就不要运行命令

     if(!args[0]) return
     if(!args[1]) return message.reply("You need to insert the second argument")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-07
    • 2020-12-26
    • 2020-10-04
    • 1970-01-01
    • 2020-12-22
    • 2021-08-22
    • 2018-07-28
    相关资源
    最近更新 更多