Adding User App Support
This commit is contained in:
@ -2,11 +2,16 @@ require("dotenv").config();
|
||||
const { glob } = require("glob");
|
||||
const { promisify } = require("util");
|
||||
const globPromise = promisify(glob);
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const Discord = require('discord.js');
|
||||
|
||||
module.exports = async (client) => {
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
|
||||
|
||||
// Slash Commands
|
||||
const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`);
|
||||
const arrayOfSlashCommands = [];
|
||||
|
||||
slashCommands.map((value) => {
|
||||
const file = require(value);
|
||||
const splitted = value.split("/");
|
||||
@ -18,7 +23,15 @@ module.exports = async (client) => {
|
||||
client.slashCommands.set(file.name, properties);
|
||||
|
||||
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
|
||||
arrayOfSlashCommands.push(file);
|
||||
|
||||
// Add integration types and contexts to support user apps
|
||||
const JSONCommand = {
|
||||
...file,
|
||||
integration_types: [0, 1], // 0 for guild, 1 for user
|
||||
contexts: [0, 1, 2], // 0 for guild, 1 for DMs, 2 for GDMs and other DMs
|
||||
};
|
||||
|
||||
arrayOfSlashCommands.push(JSONCommand);
|
||||
});
|
||||
|
||||
// Events
|
||||
@ -27,11 +40,15 @@ module.exports = async (client) => {
|
||||
|
||||
// Slash Commands Register
|
||||
client.on("ready", async () => {
|
||||
// // Register for a single guild
|
||||
// await client.guilds.cache.get("GUIDIDHERE").commands.set(arrayOfSlashCommands);
|
||||
|
||||
// Register for all the guilds the bot is in
|
||||
await client.application.commands.set(arrayOfSlashCommands);
|
||||
try {
|
||||
// Register for all the guilds the bot is in
|
||||
await rest.put(
|
||||
Discord.Routes.applicationCommands(client.user.id),
|
||||
{ body: arrayOfSlashCommands }
|
||||
);
|
||||
console.log("Successfully registered application commands.");
|
||||
} catch (error) {
|
||||
console.error("Error while registering application commands:", error);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user