Compare commits

...

2 commits

Author SHA1 Message Date
54ba45defd Added check for user and bot permissions 2022-08-22 19:18:27 +02:00
48871bc16e Add permission needed by the bot 2022-08-22 19:18:11 +02:00
2 changed files with 19 additions and 1 deletions

View file

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders'; import { SlashCommandBuilder } from '@discordjs/builders';
import { Permissions } from 'discord.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('fakeuser') .setName('fakeuser')
@ -16,6 +16,7 @@ export default {
option.setName('image') option.setName('image')
.setDescription('Optional attachment.') .setDescription('Optional attachment.')
.setRequired(false)), .setRequired(false)),
clientPermissions: [ Permissions.FLAGS.MANAGE_WEBHOOKS ],
async execute(interaction) { async execute(interaction) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
const attachment = interaction.options.getAttachment('image'); const attachment = interaction.options.getAttachment('image');

View file

@ -1,3 +1,4 @@
import { Permissions } from 'discord.js';
import db from '../../models/index.js'; import db from '../../models/index.js';
const ratelimit = {}; const ratelimit = {};
@ -30,10 +31,26 @@ export default {
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m`); console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m`);
// Owner only check
if (command.ownerOnly && interaction.user.id !== ownerId) { if (command.ownerOnly && interaction.user.id !== ownerId) {
return interaction.reply({ content: '❌ This command is reserved for the owner!', ephemeral: true }); return interaction.reply({ content: '❌ This command is reserved for the owner!', ephemeral: true });
} }
// Check if the bot has the needed permissions
if (command.clientPermissions) {
const clientMember = await interaction.guild.members.fetch(client.user.id);
if (!clientMember.permissions.has(command.clientPermissions)) {
return interaction.reply({ content: `❌ I am missing one of the following permission(s): \`${new Permissions(command.clientPermissions).toArray()}\``, ephemeral: true });
}
}
// Check if the user has the needed permissions
if (command.userPermissions) {
if (!interaction.member.permissions.has(command.userPermissions)) {
return interaction.reply({ content: `❌ You are missing one of the following permission(s): \`${new Permissions(command.userPermissions).toArray()}\``, ephemeral: true });
}
}
try { try {
const date = new Date(); const date = new Date();
if (ratelimit[userID]) { if (ratelimit[userID]) {