#Slash Command Permission BAN_MEMBERS

1 messages · Page 1 of 1 (latest)

novel tangle
#

My SlashCommand handler ```js
const fs = require('fs')
const path = require('path')
const { REST } = require('@discordjs/rest')
const { Routes } = require('discord-api-types/v9')
const { appId, guildId, token } = require('./config.json')

const commands = []
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'))

const getFilesRecursively = (directory) => {
const filesInDirectory = fs.readdirSync(directory)
for (const file of filesInDirectory) {
const absolute = path.join(directory, file)
if (fs.statSync(absolute).isDirectory()) {
getFilesRecursively(absolute)
} else {
commandFiles.push(absolute)
}
}
}
getFilesRecursively('./commands/')

for (const file of commandFiles) {
const command = require(./${file})
commands.push(command.data.toJSON())
}

const rest = new REST({ version: '9' }).setToken(token);

(async () => {
try {
await rest.put(
Routes.applicationGuildCommands(appId, guildId),
{ body: commands }
)

console.log('Successfully registered application commands.')

} catch (error) {
console.error(error)
}
})()

#

InteractionCreate.js ```js
module.exports = {
name: 'interactionCreate',
execute(interaction) {
try {
if (interaction.isCommand()) {
const command = interaction.client.commands.get(interaction.commandName)
if (!command) return
command.execute(interaction)

  } else if (interaction.isMessageComponent()) {
    const handler = interaction.client.componentHandlers.get(interaction.message.id);
    if (!handler) return;

    handler(interaction);
  }

} catch (error) {
  console.error(error)
  return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
}
if (interaction.commandName) {
  console.log(`${interaction.user.tag} triggered /${interaction.commandName} in #${interaction.channel.name}/${interaction.guild.name}.`)
}

}
}```

#

I created this to kinda isolate the topic to an specific threads, I would admit I am not sure how although I know how to do basic slash command buidling and perms

novel tangle
#

I saw that system at popular bots

#

ex. ProBot

#

I mean, you could fetch members then loop through each user who has the BAN_MEMBERS perms then add them to the perms then setDefaultPermissions as false

#

hm

#

Just a idea

#

@novel tangle Did this help you?

#

I will try somethink

#

And try figureout these thinks

#

Alright, do you want me to keep this thread opened?