【问题标题】:How to make reaction roles in discord.js?如何在 discord.js 中制作反应角色?
【发布时间】:2021-01-24 11:43:13
【问题描述】:

我想知道如何在我的 discord.js 机器人中集成反应角色。我已经尝试过messageReactionAdd 的传统方法,但似乎很难使其可扩展和可编辑,而且在我的机器人加入许多行会后它变得无法使用...... 我一直在尝试搜索使这成为可能的节点模块,但我发现的唯一东西是this,当尝试将它集成到我的机器人中时,它只是让我的命令和东西不再工作,我试图阅读如何使用该软件包制作反应角色,但无济于事,没有任何效果...... 我确实尝试过:

const ReactionRole = require("reaction-role");
const system = new ReactionRole("my-token");

let option1 = system.createOption("x:697809640147105878", "697809380137107478"); 
let option2 = system.createOption("emoji-1:720843460158698152", "708355720436777033");
let option3 = system.createOption("pepe:720623437466435626", "703908514887761930");

system.createMessage("725572782157898450", "702115562158948432", 2, null, option1, option2, option3);

system.init();

但正如我所说,它使我所有的命令都无法使用......

希望有人可以帮助我!

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可以使用discord.js-collector package 轻松实现此功能,它支持MongoDB,这是一个数据库,因此您不再需要手动编辑您的机器人!

    操作方法如下:

    const { ReactionRoleManager } = require('discord.js-collector'); //We import the discord.js-collector package that'll make reaction roles possible
    const { Client } = require('discord.js'); // We import the client constructor to initialize a new client
    const client = new Client(); //We create a new client
    
    const reactionRoleManager = new ReactionRoleManager(client, {
     //We create a reaction role manager that'll handle everything related to reaction roles
     storage: true, // Enable reaction role store in a Json file
     path: __dirname + '/roles.json', // Where will save the roles if store is enabled
     mongoDbLink: 'url mongoose link', // See here to see how setup mongoose: https://github.com/IDjinn/Discord.js-Collector/tree/dev/examples/reaction-role-manager/Note.md & https://medium.com/@LondonAppBrewery/how-to-download-install-mongodb-on-windows-4ee4b3493514
    });
    
    client.on('ready', () => {
     console.log('ready');
    });
    
    client.on('message', async (message) => {
     const client = message.client;
     const args = message.content.split(' ').slice(1);
     // Example
     // >createReactionRole @role :emoji: MessageId
     if (message.content.startsWith('>createReactionRole')) {
      const role = message.mentions.roles.first();
      if (!role)
       return message
        .reply('You need mention a role')
        .then((m) => m.delete({ timeout: 1_000 }));
    
      const emoji = args[1];
      if (!emoji)
       return message
        .reply('You need use a valid emoji.')
        .then((m) => m.delete({ timeout: 1_000 }));
    
      const msg = await message.channel.messages.fetch(args[2] || message.id);
      if (!role)
       return message
        .reply('Message not found!')
        .then((m) => m.delete({ timeout: 1_000 }));
    
      reactionRoleManager.addRole({
       message: msg,
       role,
       emoji,
      });
      message.reply('Done').then((m) => m.delete({ timeout: 500 }));
     }
    });
    
    client.login('Token');
    

    这是一个实时预览:

    您还可以使用此软件包来做一些其他非常酷的事情!像嵌入分页器,问题,是/否问题...... 大家可以找到here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 2021-09-11
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      相关资源
      最近更新 更多