【发布时间】:2020-12-10 02:22:32
【问题描述】:
我正在尝试像 dank memer 一样发出命令,当有人说 F 或 f 时,机器人会用 F 回复。我的问题是没有前缀它将无法工作,但我希望能够做到没有前缀。 这是我的代码。我使用命令处理程序。
//THIS IS THE INDEX.JS FILE
const Discord = require('discord.js');
const { default_prefix, token_bot } = require('./config.json');
const client = new Discord.Client();
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./Commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready Player One!');
});
client.on('message', message => {
if (!message.content.startsWith(default_prefix) || message.author.bot) return;
const args = message.content.slice(default_prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'f'){
client.commands.get('f').execute(message, args);
}
这个是它调用的 f.js 命令。
module.exports = {
name: 'f',
description: "This is an f command",
execute(message, args){
message.channel.send('F');
},
};
这不是我所有的 index.js 文件,它太长了。
【问题讨论】:
标签: discord.js