我想知道如何在我的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();
但是正如我所说,这使我所有的命令都无法使用...
希望有人可以帮助我!
答案 0 :(得分:0)
您可以使用discord.js-collector package轻松实现此功能,它支持MongoDB
,这是一个数据库,因此您不再需要手动编辑bot!
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!