From 2840d2b2a3752a3195b4a6184f9a039caccdeabd Mon Sep 17 00:00:00 2001 From: Charlie Laabs Date: Mon, 27 Dec 2021 11:44:44 -0600 Subject: [PATCH] Dynamically generate invite URL --- src/index.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index e9170a5..95eaf0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -354,20 +354,31 @@ function helpMessage(): Discord.MessageOptions { }; } +function generateInviteUrl(): string { + return client.generateInvite({ + scopes: ['bot', 'applications.commands'], + permissions: [ + 'VIEW_CHANNEL', + 'SEND_MESSAGES', + 'SEND_TTS_MESSAGES', + 'ATTACH_FILES', + 'READ_MESSAGE_HISTORY', + ], + }); +} + function inviteMessage(): Discord.MessageOptions { const avatarURL = client.user.avatarURL() || undefined; + const inviteUrl = generateInviteUrl(); const embed = new Discord.MessageEmbed() .setAuthor(`Invite ${client.user?.username}`, avatarURL) .setThumbnail(avatarURL as string) - .addField( - 'Invite', - `[Invite ${client.user.username} to your server](https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&permissions=105472&scope=bot%20applications.commands)` - ); + .addField('Invite', `[Invite ${client.user.username} to your server](${inviteUrl})`); return { embeds: [embed] }; } client.on('ready', async (readyClient) => { - L.info('Bot logged in'); + L.info({ inviteUrl: generateInviteUrl() }, 'Bot logged in'); await deployCommands(readyClient.user.id);