so I’m trying to make a chatbot that sends the message after the user types the prefix and the command name. The command works in general but it seems to also take in the command name. I use a command and event handler btw. This is what it looks like:
JavaScript
x
17
17
1
const fetch = require("node-fetch").default;
2
3
module.exports = {
4
name: 'chat',
5
description: "chat command",
6
execute(client, message, args){
7
8
if(!args[0]) return message.reply("To chat, do a.chat <message>");
9
fetch(`https://api.monkedev.com/fun/chat?msg=${message.content}&uid=${message.author.id}`)
10
.then(response => response.json())
11
.then(data => {
12
message.channel.send(data.response)
13
})
14
}
15
}
16
17
So when people do a.chat
without an arg after that, bot will respond To chat, do a.chat <message>
and when people put the message in there it seems to take the chat part in a.chat
as a ${message.content}
as well. How do I make it so it will ignore a.chat
and respond to only the things after it?
Advertisement
Answer
You can join all args array items into one sentence.
JavaScript
1
16
16
1
const fetch = require("node-fetch").default;
2
3
module.exports = {
4
name: 'chat',
5
description: "chat command",
6
execute(client, message, args){
7
const content = args.join(" ");
8
if(!content) return message.reply("To chat, do a.chat <message>");
9
fetch(`https://api.monkedev.com/fun/chat?msg=${content}&uid=${message.author.id}`)
10
.then(response => response.json())
11
.then(data => {
12
message.channel.send(data.response)
13
})
14
}
15
}
16