BULLETBOT
BULLETBOT

Reputation: 51

discord.js How can I delete the bots message with a Bot ID after 3 seconds?

const prefixtest = ">>"

msg = message.content.toLowerCase();

    if(msg.startsWith(prefixtest + "test")) {
        message.delete();
        setTimeout(function() {
           if{message.channel.author.id == "240254129333731328"}{ //this is the bots id
        message.delete();
        }, 3000);
    }

Sorry if my english is bad. But I can't solve this problem, i'm trying to find it on internet but nothing. How can I delete other bot messages by using their Bot ID?

Upvotes: 0

Views: 338

Answers (1)

Draityalan
Draityalan

Reputation: 710

There is an issue in your code, you are trying to get .author property on a Channel instead of a Message.

So you have to modify your if statement as following :

if (message.author.id === "240254129333731328")

Also, you can delay the deletion of a Message by adding .delete() method first parameter an object with a .timeout property in it that will represent the delay in milliseconds before the message being deleted. (See docs)

message.delete({ timeout: 3000 });

So you can modify your code this way :

if(msg.startsWith(prefixtest + "test")) {
    if (message.author.id === "240254129333731328") {
        message.delete({ timeout: 3000 });
    }
}

Upvotes: 1

Related Questions