Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

discord js message reaction remove not working

  1. User

    discord js message reaction remove not working

  2. Assistant

    As an AI language model, I do not have access to any code or programs you have created. But here are some common reasons why message reaction removal might not work:

    1. Permissions: The bot must have the Manage Messages permission to remove reactions.

    2. Incorrect unicode characters: If you are trying to remove a reaction using a custom unicode character, make sure the character is correct.

    3. Incorrect message ID: Make sure the message ID you are using is correct and refers to an existing message.

    4. Incorrect channel ID: Make sure the channel ID you are using is correct and refers to an existing channel.

    5. Incorrect reaction format: Make sure you are passing the correct format of the reaction (e.g. emoji name or custom emoji ID).

    If you have checked everything and the problem still persists, consider sharing your code or error message with the DiscordJS community to receive help.

  3. User

    I want to make bot assign role when i use custom reaction on message and remove role when remove the reaction

  4. Assistant

    To make a bot assign a role when a custom reaction is used on a message and remove the role when the reaction is removed, you can use the following code using DiscordJS:

    client.on('messageReactionAdd', async (reaction, user) => {
      if (user.bot) return; // ignore bot reactions
    
      const message = reaction.message;
      const member = message.guild.member(user);
      const roleName = 'Role Name'; // change to the name of the role you want to assign
    
      if (reaction.emoji.name === 'Custom Emoji') { // replace with your custom emoji name
        const role = message.guild.roles.cache.find(role => role.name === roleName);
        if (role) {
          member.roles.add(role);
          console.log(`Role "${roleName}" assigned to ${user.tag}`);
        }
      }
    });
    
    client.on('messageReactionRemove', async (reaction, user) => {
      if (user.bot) return; // ignore bot reactions
    
      const message = reaction.message;
      const member = message.guild.member(user);
      const roleName = 'Role Name'; // change to the name of the role you want to remove
    
      if (reaction.emoji.name === 'Custom Emoji') { // replace with your custom emoji name
        const role = message.guild.roles.cache.find(role => role.name === roleName);
        if (role) {
          member.roles.remove(role);
          console.log(`Role "${roleName}" removed from ${user.tag}`);
        }
      }
    });
    

    This code listens for reaction add and remove events, checks if the reaction is from a bot or not, finds the message and member associated with the reaction, and assigns/removes the specified role based on the custom emoji used. Replace the 'Role Name' and 'Custom Emoji' strings with the actual role name and custom emoji name respectively.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.