删除有关反应的消息|不和谐

时间:2020-08-09 19:43:00

标签: javascript node.js discord discord.js

我的问题是我想在用户反应后删除d_msg。但是它忘记了d_msg是什么并且无法删除它。我该如何解决?

function English(thechannel, message) {
    client.channels.cache.get(thechannel).send("Do u speak English?").then(d_msg => {
        d_msg.react("✅");
        d_msg.react("❌");
        client.on('messageReactionAdd', async (reaction, user) => {
            if (user.tag === theuser) {
                if (reaction.emoji.name === '✅') {
                    var role = message.guild.roles.cache.find(role => role.name === "English");
                    message.member.roles.add(role);
                }
            }
            d_msg.delete();
        });
    });
} 

1 个答案:

答案 0 :(得分:0)

const Filter = (reaction, user) => {return (reaction.emoji.name == "✅" || reaction.emoji.name == "❌") && user.id == message.author.id};
message.reply("Do you speak English? \n\n *This prompt will disappear in 30 seconds.*").then(async messageSent => {
    await messageSent.react("✅");
    await messageSent.react("❌");

    messageSent.awaitReactions(Filter, {max: 1, time: 30000, errors: ["time"]}).then(collected => {
        messageSent.reactions.removeAll();
        if (collected.first().emoji.name == "✅") {
            messageSent.edit("You do speak English!");
        } else if (collected.first().emoji.name == "❌") {
            messageSent.edit("You do not speak English!");
        }
    }).catch(e => {
        messageSent.edit("This prompt expired.");
        messageSent.reactions.removeAll();
    });
});