【发布时间】:2021-04-27 22:19:19
【问题描述】:
我想知道如何让我用 JavaScript 编写的 discord 机器人更有效地向个人/作者或服务器/频道发送消息。我可以在代码中做些什么来让我的机器人更快地发送消息吗?我有一个这样的命令处理程序:
bot.commands = new Discord.Collection();
const commandFile = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFile) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
let msg = message;
if(msg.content === 'something'){
bot.commands.get('fileSomething').execute(message);
}
我有一个名为 commands 的文件夹,其中有文件的名称,例如: 命令/fileSomething.js 在那个文件中会有:
module.exports = {
name: 'commandsList',
description: 'Sends a message saying "what?"',
execute(message){
message.channel.send(`What?`);
}
}
我只在这样的文件中保留更大的命令以保持一切井井有条。我喜欢这样的小命令:
if(message.content === 'something') {
message.channel.send(`what?`);
}
我将我的命令分开,如下所示:
if(message.content === 'something') {
message.channel.send(`what?`);
}
if(message.content === 'something') {
message.channel.send(`what?`);
}
if(message.content === 'something else') {
message.channel.send(`Now really?`);
}
如果有人可以帮助我,那将不胜感激!
【问题讨论】:
-
他们目前的速度有多快?你大致知道一个时间,你的 ping 是多少?
标签: javascript node.js discord.js