【发布时间】: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