'I'm in need of help registering for all guilds globally, can someone assist me?
I'm looking to register for all guilds globally instead of registering for just my guild ID, just so I can use slash commands in my friend's server (plus any other server it's in), yet I don't know how. I'm a bit new to discord.js.
I was wondering if someone could help me register for all guilds globally...
Extra information - I'm following reconlx's Discord.js v13 tutorials.
This is the part of my code which I need help looking at and modifying. There's a line in his command handler talking about registering for all guilds at await client.application.commands.set(arrayOfSlashCommands);, yet I'm not sure what it means...
client.on("ready", async () => {
// Register for a single guild
const guild = client.guilds.cache.get("938823675535319050")
await guild.commands.set(arrayOfSlashCommands).then((cmd) => {
const getRoles = (commandName) => {
const permissions = arrayOfSlashCommands.find(
(x) => x.name === commandName
).userPermissions;
if(!permissions) return null;
return guild.roles.cache.filter(
(x) => x.permissions.has(permissions) && !x.managed
);
};
const fullPermissions = cmd.reduce((accumulator, x) => {
const roles = getRoles(x.name);
if(!roles) return accumulator;
const permissions = roles.reduce((a, v) => {
return [
...a,
{
id: v.id,
type: 'ROLE',
permission: true,
},
];
}, []);
return [
...accumulator,
{
id: x.id,
permissions,
},
];
}, []);
guild.commands.permissions.set({ fullPermissions });
});
// Register for all the guilds the bot is in
// await client.application.commands.set(arrayOfSlashCommands);
});
Looking forward to some solutions, if you could assist, it would help a lot.
Solution 1:[1]
You can register global commands using the Client.application.commands.set() method, passing in an Array of ApplicationCommandDataResolvables into the method. However, please be aware a caveat of global commands is that they take up to an hour for changes to reflect across Discord.
See this:
client.application.commands.set(commands)
// ^^^ ^^^^^^^^
// Client is your Discord.Client Commands is the list of commands
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Compositr |
