Skip to content

Instantly share code, notes, and snippets.

@alex4108
Created April 27, 2021 06:50
Show Gist options
  • Save alex4108/42d9e506f88486d8fbe89bb3e8248193 to your computer and use it in GitHub Desktop.
Save alex4108/42d9e506f88486d8fbe89bb3e8248193 to your computer and use it in GitHub Desktop.
discordpy get giuld's birthday
import os
import discord
from datetime import datetime
from dateutil import tz
import asyncio
# Configure these 4 variables and run the bot.
# Your local timezone, beacuse tz.localtz() isn't always right.
LOCAL_ZONE = 'America/Chicago'
# Discord Bot Token
TOKEN = ''
# Guild ID where the bot should check birthday for, and announce birthday
GUILD_ID = 1
# Channel ID the bot should announce the birthday in.
CHANNEL_ID = 1
client = discord.Client()
async def getCreatedDate(client):
guild = client.get_guild(GUILD_ID)
original_tz = tz.gettz('UTC')
local_tz = tz.gettz(LOCAL_ZONE)
creation_in_utc = guild.created_at.replace(tzinfo=original_tz)
time_format = '%A %B %m, %Y %I:%M %p'
creation_in_localtz = creation_in_utc.astimezone(local_tz)
creation_formatted = datetime.strftime( creation_in_localtz, time_format )
message = "The Guild's birthday is on " + str(creation_formatted)
channel = guild.get_channel(CHANNEL_ID)
await channel.send(message)
print(message)
await client.logout()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
await getCreatedDate(client)
client.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment