-1

I'm trying to make my bot delete the 4 messages after 15 seconds, but I don't know how to make it do that.

const commando = require('discord.js-commando');

class HitOrMissCommand extends commando.Command
{
    constructor(client)
    {
        super(client,{
            name: 'hitormiss',
            group: 'simple',
            memberName: 'hitormiss',
            description: 'i bet he doesnt kiss yah!'
        });    
    }

    async run(message, args)
    {
       message.reply("I guess they never miss, huh?")
       message.reply("you got a boyfriend i bet he doesnt kiss yah!, MWAH!")
       message.reply("He gon find another girl and he wont miss yah")
       message.reply("He gon skirt and hit the dab like wiz khalifa")
    }
}

module.exports = HitOrMissCommand;
Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
CIA
  • 67
  • 1
  • 2
  • 9
  • 3
    Possible duplicate of [Discord.js: Send message and shortly delete it](https://stackoverflow.com/questions/46907207/discord-js-send-message-and-shortly-delete-it) – makertech81 Jan 08 '19 at 03:07

4 Answers4

3
if (message.content.startsWith(`!test`)) {
    await message.channel.send('Hello').then(r => r.delete({ timeout: 5000 }))
    console.log("test");
}
Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50
  • Hi, welcome to Stack Overflow! Just for you to know: when you answer a question try to post something more complete than just the code, maybe add a little explanation of what was the author's error and how you fixed it. I'm telling you this because your answer has been flagged for deletion in the "Low Quality Post" queue. You can edit your answer using the "Edit" button , or by clicking here: [edit] – Federico Grandi May 18 '20 at 17:03
1

Might want to check out this question here.

As answered in that post the best way to do that is by deleting the message after x amount of seconds.

    message.reply('Hit or miss.')
  .then(msg => {
    msg.delete(10000)
  })
  .catch(); /*Used for error handling*/

Proper credit should go to user LW001 who answered the question on the post I referred to.

makertech81
  • 898
  • 2
  • 7
  • 20
0

Since this question is similar, you could use the same technique - adding a deletion timout. After you reply, .then() delete the message with your 15 second timer (15000 milliseconds):

message.reply("I guess they never miss, huh?").then(message => message.delete(15000)).catch(err => throw err);

Or if you can't use arrow syntax:

message.reply("I guess they never miss, huh?").then(function(message) {
    message.delete(15000);
}).catch(function(err) {
    throw err;
});
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
0

It could be done like this.

var replyM = message.reply("I guess they never miss, huh?")

setTimeout(function(){
  replyM.delete
}, 1000);
SomePerson
  • 1,171
  • 4
  • 16
  • 45