简体   繁体   English

如何在 index.js [机器人的启动文件] 中创建 discord.js 命令,该命令在发送包含“hi”的消息时删除该消息

[英]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.

相关问题 在为 Discord 服务器创建 BOT 时,如何“scanf()”和“printf()”discord.js 中的用户消息? - How do I "scanf()" and "printf()" a user's message in discord.js when creating a BOT for Discord server? Discord.js -> 如何在 JavaScript 的 index.js 中使用 kick 命令(有自己的文件) - Discord.js -> How do I use the kick command (has it's own file) in index.js in JavaScript Discord.js 如何让机器人对它刚刚通过 id 在 discord 中发送的消息做出反应? - Discord.js How do I get the bot to react to the message it just sent in discord by id? 我如何让机器人在不带“\\_poll”的情况下使用 discord.js 发送轮询消息的 adv poll 命令 - How do I get a bot to send the message of the poll without the '\_poll' for an adv poll command with discord.js 当我对消息做出反应时,如何添加删除消息的代码? discord.js - how can I add code that deletes a message when I react to a message? discord.js 如何让我的 Discord.JS 机器人对其自己的直接消息做出反应? - How do I make my Discord.JS bot react to it's own Direct Message? 发送后如何删除消息 discord.js - How do I delete a message once it's been sent discord.js 您如何向对机器人发送的消息做出反应的用户发送 DM? (不和谐.JS) - How do you send a DM to users that react to a bot sent message? (Discord.JS) 当有人在 Discord.js 中键入未知命令时,如何发出“无效命令”消息? - How do I make an "Invalid Command" message when someone types an unknown command in Discord.js? 当我要求它执行命令时,为什么我的 discord.js bot 继续发送相同的消息 3-5 次 - Why does my discord.js bot keep sending the same message 3-5 times when I ask for it to do a command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM