Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用Javascript编写Discord Bot以更快地发送消息?_Javascript_Node.js_Discord.js - Fatal编程技术网

如何用Javascript编写Discord Bot以更快地发送消息?

如何用Javascript编写Discord Bot以更快地发送消息?,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,我想知道如何使用JavaScript编写的discord bot更有效地向个人/作者或服务器/频道发送消息。在代码中是否有一些东西可以让我的机器人更快地发送消息?我有这样一个命令处理程序: bot.commands = new Discord.Collection(); const commandFile = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); for(const file of comma

我想知道如何使用JavaScript编写的discord bot更有效地向个人/作者或服务器/频道发送消息。在代码中是否有一些东西可以让我的机器人更快地发送消息?我有这样一个命令处理程序:

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);
}
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?`);
}
我有一个名为commands的文件夹,其中有文件名,如: 命令/fileSomething.js 在该文件中有:

module.exports = {
    name: 'commandsList',
    description: 'Sends a message saying "what?"',
    execute(message){
        message.channel.send(`What?`);
    }
}
我只在这样的文件中保存更大的命令,以保持一切井然有序。我使用的较小命令如下所示:

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);
}
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?`);
}
我的命令是这样分开的:

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);
}
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是什么? 如果您不确定如何检查机器人程序ping,请将此代码放入命令中,它会告诉您:


message.channel.send(`他们目前的速度有多快?你大概知道一个时间,还有你的ping是什么吗?我的延迟是32ms。ping有多差?不,那不是很差,你知道消息需要多长时间才能通过吗?@HendinIt在一些命令上通常需要1-3秒,虽然不是所有命令。只有较长的命令。有些命令带有图像