問題描述
我希望我的機器人發送一條消息,確認它執行了命令,然后在超時后刪除該確認消息;以免使聊天混亂.
I am looking to have my bot send a message, confirming that it executed the command, and then delete that confirmation message after a timeout; so as not to clutter the chat.
這是我希望將其應用于當前命令的代碼示例:
Here is a code sample of my current command I would like to have it applied to:
exports.auth = 1
exports.run = (client, message, args) => {
let num = parseInt(args);
message.channel.bulkDelete(num+1)
.then(messages => console.log(`Bulk deleted ${num} messages`))
.catch(console.error);
message.channel.send(`Deleted ${num} messages!`);
message.delete(5000);
};
如果我沒有在 Message.delete() 中設置時間;行,它只是刪除我發送的消息.如果機器人發送消息的時間足夠長,它只會給我一個錯誤.
If I have no time set in the Message.delete(); line, it just deletes the message I sent. If the time is long enough for the bot to send a message, it just gives me an error.
推薦答案
你需要得到你發送的消息才能刪除它.
You need to get the message that you sent to delete it.
message.channel.send(`Deleted ${num} messages!`).then(sentMessage => {
sentMessage.delete(5000);
});
這將發送消息,消息發送后它將返回,以便您管理它(刪除/編輯).
This is gonna send the message and after the message was sent it will return it so you can manage it (delete/edit).
這篇關于讓機器人在超時后刪除自己的消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!