如何让我的不和谐机器人在其前缀运行后说些什么?

时间:2020-12-21 03:15:55

标签: discord.js

如果我说得更具体一点,我的意思是如果我说 n!say(文本),机器人只会在频道中说(文本)。

1 个答案:

答案 0 :(得分:0)

这是一个非常简单的方法, 当用户发送前缀和命令时,它只是将其拆分并返回消息。

const client = new Discord.Client();
// Set the prefix
const prefix = "!";

client.on("ready", () => {
  console.log("I am ready!");
});
 

client.on("message", (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  const args = message.content.slice(prefix.length).trim().split(/ +/);
  const command = args.shift().toLowerCase();

  if (command == "say"){ // set the command
            message.channel.send(args);
  }
});
 
client.login("Bot Token Here");

这是取自 documentation