From 4d210916c3a8c0f7a9d84b57a55452bebbfb5c03 Mon Sep 17 00:00:00 2001 From: PAW122 <70094237+PAW122@users.noreply.github.com> Date: Sun, 15 Dec 2024 19:18:19 +0100 Subject: [PATCH] reaction role slash command --- commands/normal/reaction_role.js | 82 ++++++++++++++++++++++++++++++++ handlers/emoji_handler.js | 4 +- 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 commands/normal/reaction_role.js diff --git a/commands/normal/reaction_role.js b/commands/normal/reaction_role.js new file mode 100644 index 0000000..e30080e --- /dev/null +++ b/commands/normal/reaction_role.js @@ -0,0 +1,82 @@ +const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js"); +const BotLogs = require("../../handlers/bot_logs_handler") +const BotLogsHandler = BotLogs.getInstance() + +const Database = require("../../db/database"); +const database = new Database(__dirname + "/../../db/files/servers.json"); + +const command = new SlashCommandBuilder() + .setName("reaction_role") + .setDescription("add reaction role to message") + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .addStringOption(option => option + .setName("emoji") + .setDescription("select emoji users will be reacting with") + .setRequired(true) + ) + .addRoleOption(option => option + .setName("role") + .setDescription("select role you want to give to users") + .setRequired(true) + ) + .addStringOption(option => option + .setName("message_id") + .setDescription("id of message users will be adding emoji to") + .setRequired(true) + ) + .addChannelOption(option => option + .setName("channel") + .setDescription("channel witch on is message") + .setRequired(true) + ) + .addBooleanOption(option => option + .setName("status") + .setDescription("True - on, False - off") + .setRequired(false) + ) + +async function execute(interaction, client) { + const guild = interaction.guild + const guild_id = guild.id + const role = interaction.options.getRole("role")//get role id from role + const message_id = interaction.options.getString("message_id")// msg id from options + const emoji = interaction.options.getString("emoji") + const channel = interaction.options.getChannel("channel") + const status = interaction.options.getBoolean("status") + const name = "added_by_command" + + database.init() + + if(!guild_id || !role.id || !role.name || !message_id || !channel.id || !emoji || !name) { + return await interaction.reply({ + content: "error procesing command", + ephemeral: true + }) + } + + const save_data = { + emoji: emoji, + status: status || true, + role_id: role.id, + name: role.name, + } + + database.addToList(`${guild_id}.reaction_role.${channel.id}.${message_id}`, save_data) + + BotLogsHandler.SendLog(guild.id, `Reaction role set on bot website\n channel_id: ${channel.id}\n message_id: ${message_id}`) + + return await interaction.reply({ + content: `set reaction role with emoji ${emoji} to message id: ${message_id} on channel: <#${channel.id}>`, + ephemeral: true + }) +} + +//return message if user use /help/ping +async function help_message(interaction, client) { + interaction.reply({ + content: `If any of the commands are not working properly, try using **/reload** to refresh the commands`, + ephemeral: true + }) +} + +module.exports = { command, execute, help_message }; diff --git a/handlers/emoji_handler.js b/handlers/emoji_handler.js index d656f50..62aa669 100644 --- a/handlers/emoji_handler.js +++ b/handlers/emoji_handler.js @@ -100,8 +100,6 @@ async function removeEmoji(client, reaction, user) { for (const element of data) { if (element.emoji === emoji.name && element.status === true) { - console.log("Usuwanie roli użytkownika:"); - console.log(element.role_id); try { const guild = client.guilds.cache.get(guildId); // Pobranie serwera @@ -113,7 +111,7 @@ async function removeEmoji(client, reaction, user) { // Próba zabrania roli await member.roles.remove(element.role_id); - console.log(`Rola ${element.role_id} została usunięta użytkownikowi ${member.user.tag}.`); + //console.log(`Rola ${element.role_id} została usunięta użytkownikowi ${member.user.tag}.`); } catch (err) { console.error('Błąd podczas usuwania roli - emoji_handler:', err);