mirror of
https://github.com/TheShadowEevee/Konpeki-Discord-Bot.git
synced 2025-01-11 14:38:49 -06:00
Mae the reaction buttons actually do something
This commit is contained in:
parent
217da0a524
commit
7172cb0c04
2 changed files with 80 additions and 33 deletions
14
index.js
14
index.js
|
@ -13,6 +13,9 @@ const metrics = require('./utils/pm2-metrics.js');
|
||||||
// Use a custom logging script
|
// Use a custom logging script
|
||||||
const logger = require('./utils/logging.js');
|
const logger = require('./utils/logging.js');
|
||||||
|
|
||||||
|
// Listen for (Semi-)Permenant Interactions
|
||||||
|
const interactionListener = require('./utils/interaction-trigger.js');
|
||||||
|
|
||||||
// Require the necessary discord.js classes
|
// Require the necessary discord.js classes
|
||||||
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
|
||||||
const { token, botOwner } = require('./config.json');
|
const { token, botOwner } = require('./config.json');
|
||||||
|
@ -60,7 +63,7 @@ client.once(Events.ClientReady, c => {
|
||||||
// Client "on" Events
|
// Client "on" Events
|
||||||
// Someone used an interaction
|
// Someone used an interaction
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (interaction.isChatInputCommand()) {
|
||||||
|
|
||||||
const command = interaction.client.commands.get(interaction.commandName);
|
const command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
@ -94,13 +97,18 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||||
error: error,
|
error: error,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successful Execution, report as a PM2 metric
|
// Successful Execution, report as a PM2 metric
|
||||||
// If the bot gets a lot of use, consider removing this for performance
|
// If the bot gets a lot of use, consider removing this for performance
|
||||||
metrics.interactionSuccess();
|
metrics.interactionSuccess();
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (interaction.isButton()) {
|
||||||
|
interactionListener.buttonInteraction(interaction);
|
||||||
|
}
|
||||||
|
else if (interaction.isStringSelectMenu()) {
|
||||||
|
// respond to the select menu
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Joined a server
|
// Joined a server
|
||||||
|
|
39
utils/interaction-trigger.js
Normal file
39
utils/interaction-trigger.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
const { Events } = require('discord.js');
|
||||||
|
|
||||||
|
const buttonInteraction = function(interaction) {
|
||||||
|
const splitInteraction = interaction.customId.split('-');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
if (splitInteraction[0] === 'role') {
|
||||||
|
const client = interaction.client;
|
||||||
|
const guild = await client.guilds.fetch(interaction.guildId);
|
||||||
|
const member = interaction.member;
|
||||||
|
const role = await guild.roles.fetch(splitInteraction[1]);
|
||||||
|
|
||||||
|
if (member.roles.cache.find(r => r.id === splitInteraction[1])) {
|
||||||
|
try {
|
||||||
|
member.roles.remove(splitInteraction[1]);
|
||||||
|
await interaction.reply({ content: `Removed role ${role} from ${interaction.user}!`, ephemeral: true });
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
await interaction.reply({ content: 'An error has occurred and the role was not removed. Likely I don\'t have the needed permissions!', ephemeral: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
member.roles.add(splitInteraction[1]);
|
||||||
|
await interaction.reply({ content: `Added role ${role} to ${interaction.user}!`, ephemeral: true });
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
await interaction.reply({ content: 'An error has occurred and the role was not added. Likely I don\'t have the needed permissions!', ephemeral: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: Events.InteractionCreate,
|
||||||
|
buttonInteraction,
|
||||||
|
};
|
Loading…
Reference in a new issue