Use the built in permission check for users

This commit is contained in:
Supositware 2022-08-30 22:58:23 +02:00
parent d36d086388
commit 069639a4c5
4 changed files with 10 additions and 11 deletions

View file

@ -4,9 +4,9 @@ import db from '../../models/index.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('autoresponse') .setName('autoresponse')
.setDescription('Enable or disable autoresponse'), .setDescription('Enable or disable autoresponse')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
category: 'admin', category: 'admin',
userPermissions: [PermissionFlagsBits.ManageMessages],
async execute(interaction, args, client) { async execute(interaction, args, client) {
const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } }); const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } });

View file

@ -4,9 +4,9 @@ import db from '../../models/index.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('quotation') .setName('quotation')
.setDescription('Enable or disable quotations'), .setDescription('Enable or disable quotations')
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
category: 'admin', category: 'admin',
userPermissions: [PermissionFlagsBits.ManageMessages],
async execute(interaction, args, client) { async execute(interaction, args, client) {
const quotationstat = await db.quotationstat.findOne({ where: { serverID: interaction.guild.id } }); const quotationstat = await db.quotationstat.findOne({ where: { serverID: interaction.guild.id } });

View file

@ -37,7 +37,7 @@ export default {
} }
// Check if the bot has the needed permissions // Check if the bot has the needed permissions
if (command.clientPermissions) { if (command.default_permission) {
const clientMember = await interaction.guild.members.fetch(client.user.id); const clientMember = await interaction.guild.members.fetch(client.user.id);
if (!clientMember.permissions.has(command.clientPermissions)) { if (!clientMember.permissions.has(command.clientPermissions)) {
return interaction.reply({ content: `❌ I am missing one of the following permission(s): \`${new PermissionFlagsBits(command.clientPermissions).toArray()}\``, ephemeral: true }); return interaction.reply({ content: `❌ I am missing one of the following permission(s): \`${new PermissionFlagsBits(command.clientPermissions).toArray()}\``, ephemeral: true });
@ -45,11 +45,13 @@ export default {
} }
// Check if the user has the needed permissions // Check if the user has the needed permissions
if (command.userPermissions) { /*
if (command.default_member_permissions) {
if (!interaction.member.permissions.has(command.userPermissions)) { if (!interaction.member.permissions.has(command.userPermissions)) {
return interaction.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true }); return interaction.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true });
} }
} }
*/
try { try {
const date = new Date(); const date = new Date();
@ -77,7 +79,6 @@ export default {
const args = []; const args = [];
interaction.options.data.forEach(arg => { interaction.options.data.forEach(arg => {
console.log(arg);
if (arg.type === 'MENTIONABLE') { if (arg.type === 'MENTIONABLE') {
return args.push(arg.member); return args.push(arg.member);
} }

View file

@ -7,8 +7,6 @@ import db from '../../models/index.js';
import { rand } from '../../utils/rand.js'; import { rand } from '../../utils/rand.js';
const ratelimit = {}; const ratelimit = {};
import dotenv from 'dotenv';
dotenv.config();
const { ownerId, prefix } = process.env; const { ownerId, prefix } = process.env;
const prefixs = prefix.split(','); const prefixs = prefix.split(',');
@ -308,8 +306,8 @@ export default {
} }
// Check if the user has the needed permissions // Check if the user has the needed permissions
if (command.userPermissions) { if (command.default_member_permissions) {
if (!message.member.permissions.has(command.userPermissions)) { if (!message.member.permissions.has(command.default_member_permissions)) {
return message.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true }); return message.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true });
} }
} }