Readded guild commands permissions.
Added the guild commands permissions registration to the new guild commands handling.
This commit is contained in:
@@ -9,31 +9,14 @@ module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with pong!'),
|
||||
/*
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!',
|
||||
options: [{
|
||||
name: 'input',
|
||||
type: 'STRING',
|
||||
description: 'input arg',
|
||||
required: true,
|
||||
}],
|
||||
permissions: [{
|
||||
id: '870383205306494997',
|
||||
type: 'ROLE',
|
||||
permission: false,
|
||||
},
|
||||
{
|
||||
id: '873349611358670878',
|
||||
type: 'ROLE',
|
||||
permission: false,
|
||||
},
|
||||
permissions: [
|
||||
{
|
||||
id: '870383205306494997',
|
||||
type: 'ROLE',
|
||||
permission: false,
|
||||
},
|
||||
],
|
||||
*/
|
||||
async execute(interaction) {
|
||||
const {
|
||||
value: input,
|
||||
} = interaction.options.get('input');
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
@@ -44,7 +27,7 @@ module.exports = {
|
||||
);
|
||||
|
||||
interaction.reply({
|
||||
content: `Ping ${input}`,
|
||||
content: `Ping`,
|
||||
components: [row],
|
||||
});
|
||||
|
||||
|
||||
@@ -10,22 +10,13 @@ module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('reload')
|
||||
.setDescription('Reloads a command'),
|
||||
/*
|
||||
name: 'reload',
|
||||
description: 'Reloads a command or all commands, for development purposes.',
|
||||
defaultPermissions: false,
|
||||
options: [{
|
||||
name: 'command',
|
||||
type: 'STRING',
|
||||
description: 'Name of the command to reload.',
|
||||
required: true,
|
||||
}],
|
||||
permissions: [{
|
||||
id: ownerId,
|
||||
type: 'USER',
|
||||
permission: true,
|
||||
}],
|
||||
*/
|
||||
permissions: [
|
||||
{
|
||||
id: '870383205306494997',
|
||||
type: 'ROLE',
|
||||
permission: false,
|
||||
},
|
||||
],
|
||||
async execute(interaction) {
|
||||
const {
|
||||
clientCommands,
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
const { devGuildId } = require('../../config.json');
|
||||
const { commands, permissions } = require('../../index');
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
async execute() {
|
||||
async execute(client) {
|
||||
console.log('bot ready!');
|
||||
|
||||
console.log(await commands);
|
||||
console.log(await permissions);
|
||||
|
||||
await client.application?.fetch();
|
||||
|
||||
for (let i = 0; i < commands.length; i++) {
|
||||
|
||||
const command = (await client.guilds.cache.get(devGuildId)?.commands.fetch()).find(c => c.name === commands[i].name);
|
||||
|
||||
console.log(command.id);
|
||||
|
||||
const permission = permissions[i];
|
||||
|
||||
console.log(permission);
|
||||
|
||||
await command.permissions.set({ id: command.id, permissions: permission });
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
35
index.js
35
index.js
@@ -1,21 +1,32 @@
|
||||
const Discord = require('discord.js');
|
||||
const { Client, Collection, Intents } = require('discord.js');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const {
|
||||
Client,
|
||||
Collection,
|
||||
Intents,
|
||||
} = require('discord.js');
|
||||
const {
|
||||
REST,
|
||||
} = require('@discordjs/rest');
|
||||
const {
|
||||
Routes,
|
||||
} = require('discord-api-types/v9');
|
||||
const fs = require('fs');
|
||||
|
||||
const {
|
||||
token,
|
||||
guildId,
|
||||
devGuildId,
|
||||
clientId,
|
||||
} = require('./config.json');
|
||||
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILDS],
|
||||
});
|
||||
|
||||
client.commands = new Collection();
|
||||
|
||||
const commandFolders = fs.readdirSync('./commands');
|
||||
const commands = [];
|
||||
const permissions = [];
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
|
||||
@@ -25,11 +36,16 @@ for (const folder of commandFolders) {
|
||||
|
||||
const command = require(`./commands/${folder}/${file}`);
|
||||
commands.push(command.data.toJSON());
|
||||
permissions.push(command.permissions);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
module.exports = { commands, permissions };
|
||||
|
||||
const rest = new REST({
|
||||
version: '9',
|
||||
}).setToken(token);
|
||||
|
||||
(async () => {
|
||||
|
||||
@@ -37,8 +53,9 @@ const rest = new REST({ version: '9' }).setToken(token);
|
||||
console.log('Refreshing application commands');
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commands },
|
||||
Routes.applicationGuildCommands(clientId, devGuildId), {
|
||||
body: commands,
|
||||
},
|
||||
);
|
||||
|
||||
console.log('Application commands refreshed');
|
||||
@@ -59,7 +76,7 @@ for (const folder of eventFolders) {
|
||||
|
||||
const event = require(`./events/${folder}/${file}`);
|
||||
|
||||
if(event.once) {
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args, client));
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user