Javascript Discord.js 删除单个消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45395255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:02:36  来源:igfitidea点击:

Discord.js Delete Single Message

javascriptnode.jsdiscorddiscord.js

提问by JaredCBarnes

I am currently working on creating a Discord bot using Discord.js, and I want to have a command that you can tell it ||say Helloor something and it will delete your comment, then say what you told it to.

我目前正在使用Discord.js创建一个 Discord 机器人,我想要一个命令,你可以告诉它||say Hello什么,它会删除你的评论,然后说出你告诉它的内容。

My current code is

我目前的代码是

client.on('message', message => {
   if (message.content.startsWith("||say ")) {
      message.delete(1000); //Supposed to delete message
      message.channel.send(message.content.slice(5, message.content.length));
   }
});

But this is not working.

但这是行不通的。

回答by JaredCBarnes

It turns out that I had the correct code, but my bot had to have moderator permissions.

结果证明我有正确的代码,但我的机器人必须有版主权限。

回答by James Malkin

You could've also made the bot send a message then delete 2 instead but if it works i guess that's fine :)

你也可以让机器人发送一条消息然后删除 2 但如果它有效我想这很好:)