[英]How do I create a discord.js command in index.js [The bot's startup file] that deletes the message when a message that contains "hi" was sent
I've tried to create a command where the bot waits for a message that was sent until a message contained "thebotdeletesthismessage", the bot doesn't seem to do anything, the language I've used is node.js.我试图创建一个命令,让机器人等待发送的消息,直到消息包含“thebotdeletesthismessage”,机器人似乎没有做任何事情,我使用的语言是 node.js。
The bot doesn't really responds neither delete the message, I've tried to change the code a little bit, Still nothing, I need to know what I've done wrong here.机器人并没有真正响应也没有删除消息,我尝试稍微更改代码,仍然没有,我需要知道我在这里做错了什么。
If you didn't understand something, Please let me know in the comments, And please don't close this topic, I really need help.如果您有不明白的地方,请在评论中告诉我,并且请不要关闭此主题,我真的需要帮助。
bot.on('message', message => {
if (message.content.starts("thebotdeletesthismessage")) {
message.delete
message.channel.send('No, dont send that.');
}
});
Change message.delete
to message.delete()
.将 message.delete 更改为
message.delete
message.delete()
。
First, there is no .starts()
method, you probably want to use .startsWith()
.首先,没有
.starts()
方法,您可能想使用.startsWith()
。 Also, message.delete
is not a property but a method, so you'll need to use parentheses after that.此外,
message.delete
不是属性而是方法,因此您需要在此之后使用括号。
The following code will delete every message that starts with "thebotdeletesthismessage"
and sends a message instead:以下代码将删除以
"thebotdeletesthismessage"
开头的每条消息,并改为发送一条消息:
bot.on('message', (message) => {
if (message.content.startsWith('thebotdeletesthismessage')) {
message.delete();
message.channel.send("No, don't send that.");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.