Last active
November 17, 2022 19:09
-
-
Save etahn-git/2643727a64b77302563fb3a47bf36f94 to your computer and use it in GitHub Desktop.
Discord channel that counts the amount of github followers a user has.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
import requests | |
# --------------------------------------------------------- | |
TOKEN = '' # Discord bot token | |
GITHUB_USERNAME = '' #github username (ex: 'etahn-git') | |
# Follower count channel id | |
CHANNEL_ID = | |
# Characters after the number count | |
SUFFIX = 'Github followers' | |
# Characters before the number count | |
PREFIX = '📣 | ' | |
# --------------------------------------------------------- | |
data = requests.get(f"https://api.github.com/users/{GITHUB_USERNAME}").json() | |
dataout = data["followers"] | |
intents = discord.Intents.default() | |
intents.members = True | |
bot = commands.Bot(command_prefix='!', intents=intents) | |
@bot.event | |
async def on_ready(): | |
""" Runs once the bot has established a connection with Discord """ | |
print(f'{bot.user.name} has connected to Discord') | |
# check if bot has connected to guilds | |
if len(bot.guilds) > 0: | |
print('connected to the following guilds:') | |
# list guilds | |
for guild in bot.guilds: | |
# display guild name & id, follower count | |
print(f'* {guild.name}#{guild.id}') | |
print(f'follower count: {dataout}') | |
# update the follower count | |
await update_follower_count_channel_name(guild) | |
async def update_follower_count_channel_name(guild): | |
""" updates the name of the follower count channel """ | |
if CHANNEL_ID != None and SUFFIX != None and PREFIX != None: | |
follower_count_channel = discord.utils.get(guild.channels, id=CHANNEL_ID) | |
new_name = f"{PREFIX} {dataout} {SUFFIX}" | |
await follower_count_channel.edit(name=new_name) | |
if __name__ == "__main__": | |
# launch bot | |
bot.run(TOKEN) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment