简体   繁体   English

如何让 Discord 机器人从 DM 中删除自己的消息? (Discord.js)

[英]How to make a Discord bot delete its own message from a DM? (Discord.js)

I am currently coding a Discord bot in Discord.js.我目前正在 Discord.js 中编写一个 Discord 机器人。 I was wondering whether or not it is possible to make a bot delete its own message that it sent from a DM, and if so, what the code is.我想知道是否可以让机器人删除它自己从 DM 发送的消息,如果是这样,代码是什么。 Using msg.delete() results in an error saying that you can't use that action on a DM.使用 msg.delete() 会导致错误提示您不能在 DM 上使用该操作。 Thank you in advance :D提前谢谢你:D

Here, 'recipient' is the person you are sending a message to:此处,“收件人”是您要向其发送消息的人:

recipient.send("This is sent to your dm!").then(m => {
   m.delete(10000) //Deletes the message after 10000 milliseconds (10 seconds)
}

Next time, try and do a little research first.下一次,先试着做一些研究。 You can also read the docs for discord.js which likely do have this issue.您还可以阅读可能存在此问题的 discord.js 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM