我正在尝试使我的机器人删除一条包含空格的消息,但它似乎无法正常工作。
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
}
})
但是只要我尝试执行此操作(输入命令“; start”),它就会崩溃并给出此错误。
/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)
这是怎么回事,我该如何解决?
这是我的第一个discord机器人,因此我对discord.js(甚至JavaScript)一无所知
(是的,我知道这不是全部代码,但是请相信我,如果我在第二个if语句中留下第二个代码,它将起作用)
答案 0 :(得分:0)
我猜您正在尝试删除带有超时的邮件。您的代码正在使用Discord.js v11工作。目前,最新版本为v12。您应该使用一个选项对象:
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
}
}
}