Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
- const prefix = '-';
- const fs = require('fs');
- client.commands = new Discord.Collection();
- const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
- for (const file of commandFiles) {
- const command = require(`./commands/${file}`);
- client.commands.set(command.name, command);
- }
- client.on('ready', () => {
- console.log('bot is online!');
- });
- client.on('message', message => {
- if (!message.content.startsWith(prefix) || message.author.bot) return;
- const args = message.content.slice(prefix.length).split(/ +/);
- const command = args.shift().toLowerCase();
- if (command === 'reactionrole') {
- client.commands.get('reactionrole').execute(message, args, Discord, client);
- }
- });
- client.login('YOUR_TOKEN');
- -------------------------------- ReactionRole.js --------------------------------
- module.exports = {
- name: 'reactionrole',
- description: "Sets up a reaction role message!",
- async execute(message, args, Discord, client) {
- const channel = 'YOUR_CHANNEL';
- const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "YOUR_ROLE");
- const blueTeamRole = message.guild.roles.cache.find(role => role.name === "YOUR_ROLE");
- const yellowTeamEmoji = 'YOUR_EMOJI';
- const blueTeamEmoji = 'YOUR_EMOJI';
- let embed = new Discord.MessageEmbed()
- .setColor('#e42643')
- .setTitle('Choose a team to play on!')
- .setDescription('Choosing a team will allow you to interact with your teammates!\n\n'
- + `${yellowTeamEmoji} for yellow team\n`
- + `${blueTeamEmoji} for blue team`);
- let messageEmbed = await message.channel.send(embed);
- messageEmbed.react(yellowTeamEmoji);
- messageEmbed.react(blueTeamEmoji);
- 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 === yellowTeamEmoji) {
- await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
- }
- if (reaction.emoji.name === blueTeamEmoji) {
- await reaction.message.guild.members.cache.get(user.id).roles.add(blueTeamRole);
- }
- } 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 === yellowTeamEmoji) {
- await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole);
- }
- if (reaction.emoji.name === blueTeamEmoji) {
- await reaction.message.guild.members.cache.get(user.id).roles.remove(blueTeamRole);
- }
- } else {
- return;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement