I have been trying to make a discord bot and every time, my bot sends something in the chat, I get this error written in the title in the console.
My code:
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') {
message.channel.send('pong!')
} else if (command === 'turn-off') {
if (message.author.id === '000000000000000000') {
message.channel.send('Shutting down...')
let interval0 = setInterval(turnOff, 1000)
function turnOff() {
clearInterval(interval0)
console.log('Shutting down...')
client.destroy()
}
} else {
message.channel.send(
"You don't have required permissions to use this command!"
)
}
}
})
I tried replacing "message" to "messageCreate" on the part where it was sending something in chat, or even replacing every "message" with "messageCreate".
Does anybody know what the issue could be?
>Solution :
You should listen to the messageCreate event instead of the message event:
client.on('messageCreate', message => {
/* ... */
})