因此,我试图制作一个聊天机器人,在用户输入前缀和命令名之后发送消息。该命令一般起作用,但它似乎也采用了命令名。我使用的是命令和事件处理程序。看上去是这样的:
const fetch = require("node-fetch").default;
module.exports = {
name: 'chat',
description: "chat command",
execute(client, message, args){
if(!args[0]) return message.reply("To chat, do a.chat <message>");
fetch(`https://api.monkedev.com/fun/chat?msg=${message.content}&uid=${message.author.id}`)
.then(response => response.json())
.then(data => {
message.channel.send(data.response)
})
}
}因此,当人们在没有arg的情况下做a.chat时,bot会响应To chat, do a.chat <message>,当人们将消息放进去时,似乎也会把a.chat中的聊天部分作为${message.content}来处理。我如何使它能够忽略a.chat,并且只对它之后的事情做出反应?
发布于 2021-06-09 07:42:46
您可以将所有args数组项加入到一个句子中。
const fetch = require("node-fetch").default;
module.exports = {
name: 'chat',
description: "chat command",
execute(client, message, args){
const content = args.join(" ");
if(!content) return message.reply("To chat, do a.chat <message>");
fetch(`https://api.monkedev.com/fun/chat?msg=${content}&uid=${message.author.id}`)
.then(response => response.json())
.then(data => {
message.channel.send(data.response)
})
}
}https://stackoverflow.com/questions/67899296
复制相似问题