我的反应角色代码不起作用 Discord.JS

时间:2021-05-13 20:59:40

标签: node.js

我正在尝试制作一个不和谐的机器人,我想将反应角色作为其中一项功能的功能之一,尽管当我做出反应时,它没有给出任何角色。

这是我的反应角色命令的代码:

const Discord = require('discord.js');

const client = new Discord.Client({
    partials: ["MESSAGE", "CHANNEL", "REACTION"]
});

module.exports = {
    name: 'reactionrole',
    description: "Creates Reaction Roles!",
    async execute(message, args) {
        const channel = '836281624068227093'
        const giveawayrole = message.guild.roles.cache.find(role => role.name === "Giveaway Role");
        const giveawayroleemoji = '?';

        let SelfRolesEmbed = new Discord.MessageEmbed()
            .setColor('#008B8B')
            .setTitle('Self Roles')
            .setDescription('Select the self roles you desire! More roles are soon to come, do not worry :) \n \n' + 'React with ? to never miss a giveaway');

        let messageEmbed = await message.channel.send(SelfRolesEmbed)
        messageEmbed.react(giveawayroleemoji);
        client.channels.cache.get(channel);
        message.channel.messages.cache.get()
        client.on('messageReactionAdd', async (reaction, user) => {
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;
            if (reaction.message.channel.id == '836281624068227093') {
                if (reaction.emoji.name === '?') {
                    await reaction.message.guild.members.cache
                        .get(user.id)
                        .roles.add('834823239649591306');
                }
            } else return;
        });

        // Removing reaction roles
        client.on('messageReactionRemove', async (reaction, user) => {
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;
            if (reaction.message.channel.id == '836281624068227093') {
                if (reaction.emoji.name === '?') {
                    await reaction.message.guild.members.cache
                        .get(user.id)
                        .roles.remove('834823239649591306');
                }
            } else return;
        });
    }
}

提前感谢所有回复的人! 非常感谢。

0 个答案:

没有答案