Skip to content

Commit

Permalink
feat: bot permissions check and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Sep 28, 2021
1 parent fa82db5 commit 775f410
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions commands/bot/g-spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
name: 'g-spy',
description: 'Mark an user as a g-spy',
permissions: ['MANAGE_ROLES'],
botPermissions: ['MANAGE_ROLES'],
async execute(client, message) {
const userId = /\d+/u.exec(message.content)?.toString();
const member = userId ? await message.guild.members.fetch(userId).catch(() => null) : null;
Expand Down
26 changes: 24 additions & 2 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ module.exports = {

if (!command || !interaction.inGuild()) return;

if (!interaction.member.permissions.has(command.permissions ?? 0)) {
if (!interaction.member.permissions.has(command.permissions ?? 0n)) {
return interaction.reply({
content: `You need the \`${command.permissions}\` permission to use this command`,
ephemeral: true
});
}

if (!interaction.guild.me.permissions.has(command.botPermissions ?? 0n)) {
return interaction.reply({
embeds: [{
title: 'Missinq Permissions',
description: `I need the \`${command.botPermissions}\` permission to use this command`,
color: client.config.color
}],
ephemeral: true
});
}

command.execute(client, interaction);
break;

Expand All @@ -28,13 +39,24 @@ module.exports = {
return interaction.deferUpdate();
}

if (!interaction.member.permissions.has(component.permissions ?? 0)) {
if (!interaction.member.permissions.has(component.permissions ?? 0n)) {
return interaction.reply({
content: `You need the \`${component.permissions}\` permission to use this component`,
ephemeral: true
});
}

if (!interaction.guild.me.permissions.has(component.botPermissions ?? 0n)) {
return interaction.reply({
embeds: [{
title: 'Missinq Permissions',
description: `I need the \`${component.botPermissions}\` permission to use this component`,
color: client.config.color
}],
ephemeral: true
});
}

component.execute(client, interaction);
break;
}
Expand Down
18 changes: 14 additions & 4 deletions events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ module.exports = {

const array = message.content.replace(message.prefix, '').split(' ');
const args = array.slice(1);
const [ command ] = array;

const badLetterDetected = await require('../detector/detector.js')(client, message, database);
if (badLetterDetected || !client.commands.has(command) || !message.content.startsWith(message.prefix)) return;
if (badLetterDetected || !client.commands.has(array[0]) || !message.content.startsWith(message.prefix)) return;

if (!message.member.permissions.has(command.permissions ?? 0)) {
const command = client.commands.get(array[0]);
if (!message.member.permissions.has(command.permissions ?? 0n)) {
return message.channel.send(`You need the \`${command.permissions}\` permission to use this command`);
}

client.commands.get(command).execute(client, message, args);
if (!message.guild.me.permissions.has(command.botPermissions ?? 0n)) {
return message.channel.send({
embeds: [{
title: 'Missinq Permissions',
description: `I need the \`${command.botPermissions}\` permission to use this command`,
color: client.config.color
}]
});
}

command.execute(client, message, args);
}
};
1 change: 1 addition & 0 deletions interactions/commands/g-spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
name: 'g-spy',
contextMenu: 'Mark As G Spy',
permissions: ['MANAGE_ROLES'],
botPermissions: ['MANAGE_ROLES'],
async execute(client, interaction) {
const member = interaction.options.getMember('user');

Expand Down
2 changes: 1 addition & 1 deletion interactions/components/g-spy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
name: 'g-spy',
permissions: ['MANAGE_ROLES'],
botPermissions: ['MANAGE_ROLES'],
async execute(client, interaction) {
const member = await interaction.guild.members.fetch(interaction.value).catch(() => null);
const role = interaction.guild.roles.cache.find(r => r.name === 'g-spy');
Expand All @@ -18,7 +19,6 @@ module.exports = {
}

member?.roles.remove(role);

interaction.update({
components: [{
type: 'ACTION_ROW',
Expand Down

0 comments on commit 775f410

Please sign in to comment.