BuildTheEarth / main-bot

The main bot for the BuildTheEarth Discord servers.
https://buildtheearth.net
MIT License
22 stars 13 forks source link

Automatically configure a vanity URL when level 3 is reached #17

Closed cAttte closed 3 years ago

cAttte commented 3 years ago

the server's boosting status is rather unstable. it's usually at around 32 boosts, but occasionally, it falls below 30.

these 30 boosts (or level 3) unlock a vanity invite URL, which is configured to discord.gg/buildtheearth. unfortunately, Discord unsets this setting when level 3 is lost, and it does not restore it once it's regained.

the permission required to update the vanity URL is MANAGE_SERVER, which is only possessed by the Admin role. as known, administrators are not quite the fastest to respond to this type of occasion.

ideally, the bot would detect whenever level 3 is reached, and accordingly update this setting. if needed, a new vanity field could be added to the configuration, as hard-coding this type of value does not ring the prettiest bells.


on the technical side, the Discord WebSocket Gateway does not provide a guildPremiumSubscription event, or similar.

the bot could either subscribe to the guildMemberUpdate event to check for the configured server booster role being added to a member, or subscribe to the message event and check for Message#type to be "USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3".

once again, changing the vanity URL of a guild is not documented (and therefore it's not included in discord.js...), but making a PATCH request to /guilds/{guild.id}/vanity-url will work — see Get Guild Vanity URL & discord/discord-api-docs#519. the best option for this would probably be implementing a custom setVanityCode() method in Guild (and possibly even PR it into discord.js).


overall, the implementation of this feature will be kinda hacky, but it will be worth it!

yyrichy commented 3 years ago

nice

XboxBedrock commented 3 years ago

oh god this is gonna be sketch af