简体   繁体   English

我正在尝试使用我自己的不和谐机器人来制作反应角色,但由于某种原因,即使它添加了反应,它也没有添加角色

[英]I'm trying to make reaction roles using my own discord bot but for some reason it doesn't add the role even though it adds the reactions

I'm trying to make a discord bot that adds roles from reactions.我正在尝试制作一个不和谐的机器人,从反应中添加角色。 I've been following a tutorial from CodeLyon and I hit a snag and I cant find a fix我一直在学习 CodeLyon 的教程,但遇到了障碍,找不到修复方法

Basically, I got the bot to send a embed message and it adds the reactions to the message.基本上,我让机器人发送一条嵌入的消息,并将反应添加到消息中。 But it doesn't add the roles.但它没有添加角色。

module.exports = {
  name: "reactionrole",
  description: "Sets up a reaction role message!",
  async execute(message, args, Discord, client) {
    const channel = "907732565685846036";
    const ACRole = message.guild.roles.cache.find(
      (role) => role.name === "Animal Crossing"
    );

    const ACEmoji = "🐸";

    let embed = new Discord.MessageEmbed()
      .setColor("#e42643")
      .setTitle("Choose which games you play!")
      .setDescription(
        "React to add the games you play as a role (and receive pings)\n\n" +
          `${ACEmoji} for Animal Crossing\n`
      );

    let messageEmbed = await message.channel.send({ embeds: [embed] });
    messageEmbed.react(ACEmoji);

    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 === ACEmoji) {
          await reaction.message.guild.members.cache
            .get(user.id)
            .roles.add(ACRole);
        }
      } 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 === ACEmoji) {
          await reaction.message.guild.members.cache
            .get(user.id)
            .roles.remove(ACRole);
        }
      } else {
        return;
      }
    });
  },
};

In my main.js (some people use index.js) file I had to change const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE'] }, { partials: ["MESSAGE", "CHANNEL", "REACTION" ] })在我的 main.js(有些人使用 index.js)文件中,我不得不更改const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE'] }, { partials: ["MESSAGE", "CHANNEL", "REACTION" ] })

to

const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS'] }, { partials: ["MESSAGE", "CHANNEL", "REACTION" ] })

It fixed it for a little bit but it randomly stopped working again.它修复了一点,但它又随机停止工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试为我的机器人在 discord.js 中创建一个自动角色 function 但它不起作用 - I'm trying to make an autorole function in discord.js for my bot but it doesn't work 如何让机器人在不同的反应中添加不同的角色? - How can I make a bot add different roles on different reactions? 我的不和谐机器人并不总是在反应事件时触发 - My discord bot doesn't always trigger on reaction event Discord 机器人消息不收集反应 - Discord bot message doesn't collect reactions 我正在尝试制作一个 Discord 机器人,只有 jQuery 的一些功能可用; ajax 没有 - I'm trying to make a Discord Bot, only some features of jQuery works; ajax doesn't 即使用户不拥有角色,机器人也会为用户分配角色 - Bot assigns user a role, even if user doesn't own role 我正在尝试让 discord 机器人根据有人加入服务器后的时间赋予角色 - I'm trying to make a discord bot give roles base on the time since somebody has joined the server 我正在尝试在带有书签的网站中制作一个 mod 菜单,但由于某种原因它没有显示 - I'm trying to make a mod menu in a website with bookmarklet, but for some reason it doesn't show up 试图通过反应发出命令来赋予角色。 - discord.js - Trying to make an command to give roles by reactions. - discord.js 我的 discord 测试机器人返回“您无权使用该命令”,即使我在频道中明确为我的角色提供了该命令 - My discord test bot returns 'You do not have the permission to use that command' even though I clearly have it on the channel for my role
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM