Skip to content

Commit

Permalink
reaction role slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
PAW122 committed Dec 15, 2024
1 parent 6394912 commit 4d21091
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
82 changes: 82 additions & 0 deletions commands/normal/reaction_role.js
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 1 addition & 3 deletions handlers/emoji_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down

0 comments on commit 4d21091

Please sign in to comment.