提问者:小点点

如何在discord.js上发出“say”命令?


我最近做了一个不和谐的机器人,有几个功能,这个机器人有一个先进的命令处理程序,我想知道如何做一个命令,在那里,机器人说什么你告诉它。

示例:“.say(消息)”

bot以“(消息)”响应

这是我的命令处理程序

const Discord = require ('discord.js');
const { FILE } = require('dns');

const client = new Discord.Client();

const prefix = ".";

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('alpha 0.2.9, IM ONLINE!!!');
});

client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/)
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        client.commands.get('ping').execute(message, args);
    } else if (command == 'pong'){
        client.commands.get('pong').execute(message, args);
    } else if (command == 'help'){
        client.commands.get('help').execute(message, args, Discord);
    } else if (command == 'kill'){
        client.commands.get('kill').execute(message, args);
    } else if (command == 'quote'){
        client.commands.get('quote').execute(message, args);
    } else if (command == 'kiss'){
        client.commands.get('kiss').execute(message, args);
    } else if (command == 'hug'){
        client.commands.get('hug').execute(message, args);
    } else if (command == 'pet'){
        client.commands.get('pet').execute(message, args);   
    } else if (command == 'bruh'){
        client.commands.get('bruh').execute(message, args);
    }
})

client.login('no')

没有关于如何使用高级命令处理程序执行此操作的教程

现在的机器人是为了好玩,但我可能会使它成为适度。


共1个答案

匿名用户

使用字符串#split()数组#slice()数组#join()的组合

else if (command === 'say') {
   const sayMessage = message.content.split(' ').slice(1).join(' ');

   message.channel.send(sayMessage);
}