I'm trying to make my bot delete a message if it contains a space, but it does not seem to work.
oneword.on('message', message => {
if (Attivo == true) {
messaggio.push(message.content)
console.log("il bot riceve un messaggio")
if (message.content.includes(" ")) {
message.delete(200)
}
return
}
})
But whenever I try and do it (i enter the command ";start") it crashes and gives this error.
/home/broog/discord-bot-terzo/node_modules/discord.js/src/structures/Message.js:501
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
^
TypeError [INVALID_TYPE]: Supplied options is not an object.
at Message.delete (/home/broog/discord-bot-terzo/node_modules/discord.js/src/structures/Message.js:501:44)
at Client.oneword.on.message (/home/broog/discord-bot-terzo/index.js:16:55)
at Client.emit (events.js:203:15)
at MessageCreateAction.handle (/home/broog/discord-bot-terzo/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/broog/discord-bot-terzo/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/broog/discord-bot-terzo/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/broog/discord-bot-terzo/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/home/broog/discord-bot-terzo/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/broog/discord-bot-terzo/node_modules/ws/lib/event-target.js:125:16)
at WebSocket.emit (events.js:198:13)
What's happening here and how do I fix this?
It's my first discord bot so I'm really unexperienced in discord.js (and even JavaScript)
(Yes I know this isn't all of the code but trust me it works if I leave that second if statement)
I guess you're trying to delete the message with a timeout. Your code was working using Discord.js v11. At this time, the latest version is v12. You should use an option object:
oneword.on ('message', message=>{
if(Attivo == true){
messaggio.push(message.content)
console.log("il bot riceve un messaggio")
if (message.content.includes(" ")) {message.delete({ timeout: 200 })}
return
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.