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

在不和谐中有反应问题。js

司马高明
2023-03-14

几个月来,我一直在我的不和谐机器人中使用相同的反应角色代码,但是突然在过去的几天里,机器人不会给任何人任何角色。我不知道怎么了。我的机器人有权限,我不会返回任何类型的错误消息。这是我添加和删除角色的代码。

client.on('messageReactionAdd', async (reaction, user) => {
 if (reaction.message.partial) await reaction.message.fetch();
 if (user.bot) return;
 if (!reaction.message.guild) return;
 if (reaction.message.channel.id === '741419143315587072') {
  if (reaction.emoji.name === 'Mario1') {
   await reaction.message.guild.members.cache
    .get(user.id)
    .roles.add('756305200414720022');
  }
 }
});

client.on('messageReactionRemove', async (reaction, user) => {
 if (reaction.message.partial) await reaction.message.fetch();
 if (user.bot) return;
 if (!reaction.message.guild) return;
 if (reaction.message.channel.id === '741419143315587072') {
  if (reaction.emoji.name === 'Mario1') {
   await reaction.message.guild.members.cache
    .get(user.id)
    .roles.remove('756305200414720022');
  }
 }
});

Partials在这里定义。

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

这是我希望人们对这个角色做出反应的信息。

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

module.exports.run = async (client, message, args) => {
 if (!message.member.hasPermission('ADMINISTRATOR')) {
  return message.reply(
   'you lack sufficiant permissions to execute this command.'
  );
 }
 let embed = new Discord.MessageEmbed()
  .setTitle('Fighters 1-18')
  .setColor('#cf200a');
 let msgEmbed = await message.channel.send(embed);
 msgEmbed.react('695364267494342718'); //Mario
};

module.exports.config = {
 name: '1-18',
 description:
  'Sends a message and reacts to it with all the fighters from numbers 1-18.',
 usage: '!1-18',
 accessableby: 'Moderators',
 aliases: [],
};

共有1个答案

厉钊
2023-03-14

这是一个实用的示例,因此您可以修改细节、添加条件格式或其他内容。

//Call External Required Libraries
const Discord = require('discord.js');

//Create a Discord Client Object 
const asilem = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });

//Call Developer Required Libraries
const { token, prefix } = require('./package.json'); // Taking token from configJson    

//Launch the client and must be executed one time
asilem.once('ready', () => {
    console.log('Ready!');
});

//Get App Token from config.json file
asilem.login(token);

 asilem.on('messageReactionAdd', async (reaction, user) => {
      // When we receive a reaction we check if the reaction is partial or not
    if (reaction.partial) {
        // If the message this reaction belongs to was removed the fetching might 
       result in an API error, which we need to handle
        try {
            await reaction.fetch();
        } catch (error) {
            console.error('Something went wrong when fetching the message: ', error);
            // Return as `reaction.message.author` may be undefined/null
            return;
        }
    }

    // Assign role with reaction
    reaction.message.guild.members.cache.get(user.id).roles.add('760324295674298378');
  });
 类似资料:
  • 我目前正在编写一个discord bot反应角色命令。 一切都很顺利,但我有一个问题。 当我启动机器人并运行创建嵌入的命令时,一切都很好。问题是当我对信息做出反应时,它并没有给我这个角色。这是我的代码:

  • 如何检查消息中添加了哪些反应?我想创建一个带有一些反应的命令(!roles),如果您单击其中一个,您将获得一个角色。我试着这样做: 但它不起作用。

  • 我们使用了一个管理角色的免费工具,在不和谐服务器上犯了一个错误。我就不点名了。该工具不允许我们编辑包含所有表情符号和相关角色的原始嵌入。此外,不和谐似乎不允许您编辑其他用户的消息,即使您拥有服务器。这很有道理。 所以我们剩下的就是创建一个新的角色消息,它看起来像旧的角色消息,并向其中添加反应。然而,我们不希望每个人都必须回去重做他们的反应,因为移动消息不会对他们现有的角色产生任何影响。我们仍然希望

  • 所以我正在制作一个机器人,我想为“userinfo”命令制作一个很酷的小功能,我很少或几乎从来没有在机器人上看到过。 我目前被活动/游戏信息所困扰。我已经为用户的所有活动制作了一张地图,以防用户有多个活动。 例如:用户同时拥有自定义状态和正在收听Spotify或玩游戏。我已经设法制作了一个地图,上面写着用户正在玩的游戏,我想让自定义状态也显示出来。不幸的是,对于自定义状态,它只写“自定义状态”,而

  • 我正试图做出一个依靠反应的帮助,我得到了这个代码 但它不工作,我得到一个错误。 错误是: 上述例外是以下例外的直接原因: Traceback(最近一次调用最后):文件"C:\用户\PC\AppData\本地\程序\Python\Python38-32\lib\site-包\discord\client.py",第312行,在_run_event等待coro(*args,**kwargs)文件"C:

  • 我正在为我的不和谐发出一个临时静音命令,但我不知道应该使用什么命令,没有错误。这是一个意想不到的结果,如果你能告诉我如何添加一个理由,那就太好了!。命令在下面。 但该命令既不使目标静音或临时静音,也不发送任何错误,它只是说“出了问题”。我也找不到一个命令,在其中我可以得到的成员谁调用了命令行等待机器人。比如({}被{}禁用了)。格式化(target.notice,message.author))消