Rebuild Bot Guide ID

So, at the moment my config consists of "guildId": "xxxxxxxxxxxxxxxx", which is the guideID. I want to basically remove this so anyone can invite the bot into there own discord server and put the bot into there discord. Only problem being is, I have to manually do node deploy.js to build the commands for them to show up in the discord, is there anyone who would be happy to help remake this so anyone can invite the bot to there own servers etc?
13 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
NyR
NyR2mo ago
Deploy the commands globally instead of guild based, that way it'll be available to anyone who invites the bot
d.js docs
d.js docs2mo ago
Suggestion for @GradientWizzard: :guide: Creating Your Bot: Registering slash commands - Command registration > Global commands read more
GradientWizzard
GradientWizzard2mo ago
So, I'm guessing I just do it like this
// deploy commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(
Routes.applicationGuildCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
// deploy commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(
Routes.applicationGuildCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
NyR
NyR2mo ago
You just removed the guild id there, route is still the same, follow the guide i linked It should be Routes.applicationCommands(clientId) for global commands Also you may need to reset your guild commands (in every guild where you registered it) if you don't want it to be duplicated (as both guild commands and global commands are considered different)
d.js docs
d.js docs2mo ago
If you have duplicate commands on your server, you registered both global and guild commands. You can remove the duplicates by resetting either the global or guild commands - Resetting global commands: rest.put(Routes.applicationCommands(clientId), { body: [] }) - Resetting guild commands: rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
GradientWizzard
GradientWizzard2mo ago
Okay, so that's done, is there a way to see what guilds your discord bot has been added to?
d.js docs
d.js docs2mo ago
:property: Client#guilds All of the guilds the client is currently handling, mapped by their ids - as long as sharding isn't being used, this will be every guild the bot is a member of
NyR
NyR2mo ago
<Client>.guilds.cache will return a collection of all the guilds your bot is in Assuming you have guilds intent (which you should for discordjs to work properly)
GradientWizzard
GradientWizzard2mo ago
I have indeed
GradientWizzard
GradientWizzard2mo ago
So, I get this error, but works perfect if I do it on my own machine and not the linux
No description
GradientWizzard
GradientWizzard2mo ago
const { SlashCommandBuilder } = require('discord.js');
const fetch = require('node-fetch');

module.exports = {
data: new SlashCommandBuilder()
.setName('fetchguilds')
.setDescription('Fetches the list of guilds the bot is in.'),
async execute(interaction) {
// Check if the user issuing the command is the bot owner
if (interaction.user.id !== '209986630654623744') {
return interaction.reply({ content: 'You do not have permission to use this command, contact GradientWizzard.', ephemeral: true });
}

// Fetch the list of guilds the bot is in
try {
const guilds = interaction.client.guilds.cache.map(guild => guild.name);
return interaction.reply({ content: `Guilds:\n${guilds.join('\n')}` });
} catch (error) {
console.error(error);
return interaction.reply({ content: 'Failed to fetch guilds.', ephemeral: true });
}
},
};
const { SlashCommandBuilder } = require('discord.js');
const fetch = require('node-fetch');

module.exports = {
data: new SlashCommandBuilder()
.setName('fetchguilds')
.setDescription('Fetches the list of guilds the bot is in.'),
async execute(interaction) {
// Check if the user issuing the command is the bot owner
if (interaction.user.id !== '209986630654623744') {
return interaction.reply({ content: 'You do not have permission to use this command, contact GradientWizzard.', ephemeral: true });
}

// Fetch the list of guilds the bot is in
try {
const guilds = interaction.client.guilds.cache.map(guild => guild.name);
return interaction.reply({ content: `Guilds:\n${guilds.join('\n')}` });
} catch (error) {
console.error(error);
return interaction.reply({ content: 'Failed to fetch guilds.', ephemeral: true });
}
},
};
NyR
NyR2mo ago
The code you sent does not match the error, according to the error you missed , sperator before ephemeral