N
N
Nikita Volkov2020-11-02 15:10:43
Python
Nikita Volkov, 2020-11-02 15:10:43

How to delete a message by reaction in discord?

When a kick / ban / mute the user appears a message about this. I want a reaction to appear under it, by clicking on which the message was deleted, BUT for this to work ONLY for the admin who used the command

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Kudrin, 2020-11-02
@HepkaPlay

It will roughly look like this.

client.on('message', async(message) => {
    if(message.author.bot || message.author == client.user) return;
    if(message.content.startsWith('/ban')) {
        // Баним пользователя, затем отправляем сообщение

        let author = message.author; // На всякий случай заключаем администратора в переменную author.
        message.channel.send('забанил человека').then(msg => {
            msg.react('reaction') // Заместо reaction ставим реакцию, которую нужно.
            const filter = (reaction, user) => reaction.emoji.name === "reaction" && user.id == author.id; // Создаем фильтр для коллектора
            const collector = msg.createReactionCollector(filter, { time: 43200000 }); // Создаем сам коллектор

            collector.on('collect', async(reaction, user) => { // Можно использовать не асинхронную функцию. Если она не нужна, просто убираем 'async'.
                msg.delete(); // Удаляем сообщение, при нажатии на реакцию. (Если нужно удалить сообщение через время, используем 'msg.delete({ timeout: time_in_ms })')
            })
            collector.on('end', () => {
                return; // Здесь функции которые нужно выполнить после остановки коллектора.
            })
        })
    }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question