Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Discord.js Delete Single Message

Writer Andrew Henderson

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.

1

2 Answers

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

0
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 }
});

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy