当前位置: 首页 > 知识库问答 >
问题:

带有自定义表情符号的反应角色

赵飞语
2023-03-14

我有问题得到反应角色的工作与自定义表情符号。如果我使用不和谐表情符号,它会嵌入消息,创建反应,并在点击反应时应用角色。

然而,如果我使用一个自定义的emoji,它会嵌入消息并创建正确的反应,但是它不提供当emoji被点击时的角色。

我使用了相同的编码,当交换不和谐和自定义的表情符号,唯一的改变是表情符号的ID。

我使用的完整代码是:

const { MessageReaction } = require("discord.js");

module.exports = {
    name: "reactionrole",
    description: "Sets up a reaction role message!",
    async execute(message, args, Discord, client) {
        const channel = "764347631081881660";
        const sheRole = message.guild.roles.cache.find((role) => role.name === "She/Her");
        const heRole = message.guild.roles.cache.find((role) => role.name === "He/Him");
        const theyRole = message.guild.roles.cache.find((role) => role.name === "They/Them");

        const sheEmoji = client.emojis.cache.get("805419160497946634");
        const heEmoji = client.emojis.cache.get("795488864721829928");
        const theyEmoji = client.emojis.cache.get("795871326446419968");

        let embed = new Discord.MessageEmbed()
            .setColor("#e42643")
            .setTitle("Self Assignable Roles")
            .setDescription(
                "To Join one of our self-assignable roles, click/tap the reaction with the appropriate emoji for that role. (Note that this is purely for fun and for helpful tags & inclusivity.) By doing this we are hoping to better assist everyone in how they can address others. This also adds helpful knowledge of when someone may be on for trades, events etc.This is also not mandatory but highly recommended. isaheart \n\n" +
                    `List of corresponding emojis & roles:\n\n` +
                    `Identify yourself:\n` +
                    `:judy: She/Her\n` +
                    `:raymond: He/Him\n` +
                    `:zucker: They/Them\n\n` +
                    `Removing your reaction will also remove the role from yourself. You can have multiple roles so go ahead and choose one from each category ^^If you have any questions please feel free to reach out to any of our Admin`
            );

        let messageEmbed = await message.channel.send(embed);
        messageEmbed.react(sheEmoji);
        messageEmbed.react(heEmoji);
        messageEmbed.react(theyEmoji);

        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 === channel) {
                if (reaction.emoji.name === sheEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(sheRole);
                }
                if (reaction.emoji.name === heEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(heRole);
                }
                if (reaction.emoji.name === theyEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(theyRole);
                }
            } else {
                return;
            }
        });

        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 == channel) {
                if (reaction.emoji.name === sheEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(sheRole);
                }
                if (reaction.emoji.name === heEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(heRole);
                }
                if (reaction.emoji.name === theyEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(theyRole);
                }
            } else {
                return;
            }
        });
    },
};

我们将非常感谢对此提供任何帮助。

共有2个答案

翟泰
2023-03-14

如果你想为你的机器人使用自定义表情符号,确保机器人在一个服务器上有你想要的自定义表情符号,我建议做一个新的服务器专用于此。接下来,您所需要做的就是在表情符号之前加上一个\。然后,它应该发送如下内容:<:emoji_name:0123456>。您只需将其添加到所需变量的定义中。

牛景同
2023-03-14

您正在使用emoji#name作为自定义表情符号和默认表情符号。问题是自定义表情符号没有emoji#name属性(默认表情符号也是一样,它们没有emoji#id)。

要解决这个问题,您需要将emoji#id专门用于自定义表情符号,或者使用emoji#identifier

这意味着您可以

  • reaction.emoji.id===heemoji.id
  • 反应.emoji===heemoji(非100%安全)
  • reaction.emoji.identifier===heemoji.identifier
 类似资料:
  • 我在尝试让我的discord机器人添加基于表情符号反应的角色时遇到问题。当我使用该命令时,我的机器人将嵌入消息和表情符号,但表情符号不可点击。另外,当我键入命令时,我会得到未处理的PromisejectionWarning:DiscordAPIError:Unknown表情符号错误(节点:12916) }

  • 我有一个名为的自定义验证器函数。 如果我像这样设置表单,一切都工作了: 但是,如果我使用这样的表单生成器设置表单: 如果构造函数中将定义为,则验证不起作用。所谓“不工作”,我的意思是表单的valid属性不正确,在控制台中我看不到预期的输出(使用第一个方法显示)。 我没有在第二个方法中正确定义验证器(如果是这样的话,应该如何定义它),或者FormBuilder有什么东西使自定义验证器不可用?

  • 我正试图用在中添加自定义分隔符,但没有成功,我已经搜索了很多,并查看了下面提到的答案,但这对我没有帮助 链接1 链接2 链接3 我想在的每个项之间加上黑线,如下所示。 我在每行之间都有水平线,但不知道如何在列之间得到这些线。 chintan Soni的答案工作很好,但它只在一个场景中产生问题,当我有5个视图时,它还显示了其他3个项目的分界线,如下所示:

  • 下面是用Discord.js编写的不和谐机器人的代码片段: 它在控制台中获得以下输出: 我可以在输出中看到。我想得到这两个用户的对象列表。如何做到这一点?

  • 问题内容: 我必须创建一个将具有圆角,边框,阴影的自定义,其方法被重写以提供自定义绘图代码,并通过该代码将多条直线绘制到视图中(我在这里需要使用快速,轻便的方法,因为许多这些视图中的一个可以呈现)。 我当前面临的问题是,一旦在视图类中进行覆盖(即使其中没​​有任何自定义代码),阴影也将不再适用于圆角。请参见附件中的图片: 在视图控制器中,我使用以下代码: 在覆盖的情况下,我将使用类似: 但是如上所

  • 获取系统emoji表情,实现表情键盘,输入框能够随着输入文字的长度而自动增长,模仿微信键盘,能够切换文字键盘和表情键盘。 [Code4App.com]