Hey guys I'm currently developing a discord application that is connected to a firebase app. In this discord application I created a command /init-hub that allow user to create a document in this firebase firestore with the reference equal to the discord server id (one hub = one server).
Here is my problem,
I created this command :
run: async (client: Client, interaction: BaseCommandInteraction) => {
if (!interaction.guildId) {
await interaction.followUp({
ephemeral: true,
content: 'Unable to create HUB for this server, contact us'
});
return;
}
const content = "Hub generated";
// Get firestore db
const db = admin.firestore();
// ID OF THE SERVER
const guild = client.guilds.cache.get(interaction.guildId);
console.log(guild);
The log returned here is "undefined" but before I remove my app from my server and add it again (I Had an issue) this function worked perfectly.
Should I change the way I'm "fetching" my guild ? is there another way to do it with just the ID ?
I think my problem is coming from the "scope" or permissions in the invite URL for my application if anybody could tell me how I should create this URL here is mine :
https://discord.com/api/oauth2/authorize?client_id=[CLIENT_ID]&redirect_uri=https%3A%2F%2Fdiscordapp.com%2Foauth2%2Fauthorize%3F%26client_id%3D[CLIENT_ID]%26scope%3Dguilds%2520applications.commands&response_type=code&scope=guilds%20guilds.members.read%20rpc.voice.read%20applications.commands
Also in my discord client I specified those Intents :
const client = new Client({
intents: [
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.DIRECT_MESSAGES,
]
});
UPDATE :
When I try with this code :
const guild = await client.guilds.fetch(interaction.guildId);
I receive this error : DiscordAPIError: Missing Access