Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.js Delete Single Message

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 Hello or something and it will delete your comment, then say what you told it to.

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.

like image 249
jcb1032 Avatar asked Jul 30 '17 00:07

jcb1032


People also ask

Can you delete a message on Discord?

1. Open your Discord account and hover over the message to click on the three dots that appear in the upper-right corner. 2. Select "Delete Message."

How do you make Discord bot delete its own message?

To start the auto-deletion process, just open the channel in your Discord server that you want to delete messages in and type @AutoDelete start 24h. You can replace 24h with the time that you may want to delete like 5h or 30s, etc. But remember, the maximum time parameter is an hour.


2 Answers

client.on('message', message => {
   if (message.content.startsWith("||say ")) {

      let input = message.content.split(" ").slice(1).join(" ") // Removes the prefix

      message.delete() // Deletes the message
      message.channel.send(input))//.then(msg=>msg.delete({timeout:"5000"}) <- if you want delete it with delay and sends the finished text
   }
});
like image 68
Maesket Avatar answered Sep 18 '22 07:09

Maesket


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

like image 45
jcb1032 Avatar answered Sep 22 '22 07:09

jcb1032