如何在静音到期后恢复静音之前存储用户的角色

时间:2020-04-11 13:01:46

标签: javascript discord.js

我想做到这一点,以便在我使用户静音后,便删除并存储了他们的角色,以便一旦取消静音,他们就可以恢复角色

let muterole = message.guild.roles.cache.find(r => r.name === "muted")
        if (!muterole) {
            try {
                muterole = await message.guild.roles.create({
                    data: {
                        name: "muted",
                        color: "#514f48",
                        permissions: []
                    }
                })
                message.guild.channels.cache.forEach(async (channel) => {
                    await channel.createOverwrite(muterole, {
                        SEND_MESSAGES: false,
                        ADD_REACTIONS: false,
                        SEND_TTS_MESSAGES: false,
                        ATTACH_FILES: false,
                        SPEAK: false,
                        CONNECT: false,
                    })
                })
            } catch (e) {
                console.log(e);
            }
        }
        mutee.roles.set([])
        mutee.roles.add(muterole.id).then(() => {
            mutee.send(`Hello, you have been muted in ${message.guild.name} for ${reason || "No Reason"}`).catch(err => console.log(err))
            const sembed = new MessageEmbed()
                .setColor("GREEN")
                .setAuthor(message.guild.name, message.guild.iconURL())
                .setDescription(`${mutee.user.username} was successfully muted.`)
            message.channel.send(sembed);
        })

2 个答案:

答案 0 :(得分:1)

只需创建一个对象,并在密钥中包含他的ID,并在包含他的角色的每个ID的数组中创建他的角色,然后将其保存到带有fs库的JSON文件中,就很容易使用,而您不需要不必安装,它已集成在节点中。

答案 1 :(得分:0)

使用数据库修复-quick.db