【问题标题】:Kill a Command Handler script in discord.js杀死 discord.js 中的命令处理程序脚本
【发布时间】:2021-05-10 05:45:29
【问题描述】:

我正在使用 discord.js 开发一个不和谐的机器人,但我不擅长编码。我想要做的是得到一个命令来启动一个进程来询问然后接受用户输入。所以机器人会问一些东西,它会听用户的消息。但我也想要一个命令来停止这个询问过程。有没有办法杀死这个特定命令的命令处理程序而不是 main.js?我的 main.js 和我使用的命令处理程序:

const Discord = require('discord.js')
const bot = new Discord.Client()
const fs = require('fs')
bot.commands = new Discord.Collection()

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'))
for(const file of commandFiles){
    const command = require(`./commands/${file}`)
 
    bot.commands.set(command.name, command)
}

bot.on('message', message =>{
    if(command === 'ask'){
        bot.commands.get('ask').execute(message,args, bot)
    }
}

命令处理程序:

module.exports = {
    name: 'ask',
    execute(message, args, bot){
         bot.on('message', msg =>{
             if(msg.content.toLowerCase() == "endask"){
                // So is there anyway here to only kill this command handler
             }
         }
    }

【问题讨论】:

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


    【解决方案1】:

    首先,您可能应该尝试更多地了解命令处理程序,因为您似乎在其中放置了一个事件,以及您“结束”它的方式将使用“return”和它将停止你的命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-30
      • 2021-11-04
      • 2015-12-22
      • 2021-11-02
      • 2020-06-09
      • 2021-08-01
      • 2020-06-17
      • 1970-01-01
      相关资源
      最近更新 更多