mirror of
https://gitlab.com/pancakes1234/wdiscordbotserver.git
synced 2025-06-16 07:14:21 -06:00
Edit world_time.py
This commit is contained in:
parent
6384a67f20
commit
c889e9be0f
@ -9,13 +9,12 @@ class WorldTime(commands.Cog):
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@app_commands.command(name="worldtime", description="Display time in different timezones")
|
@app_commands.command(name="world_time", description="Display timezones")
|
||||||
@app_commands.describe(timezone="The timezone to display (optional)")
|
@app_commands.describe(timezone="The timezone to display (optional)")
|
||||||
async def worldtime(self, interaction: discord.Interaction, timezone: str = None):
|
async def worldtime(self, interaction: discord.Interaction, timezone: str = None):
|
||||||
now = datetime.datetime.now(datetime.timezone.utc)
|
now = datetime.datetime.now(datetime.timezone.utc)
|
||||||
|
|
||||||
if timezone:
|
if timezone:
|
||||||
# User specified a timezone
|
|
||||||
try:
|
try:
|
||||||
tz = pytz.timezone(timezone)
|
tz = pytz.timezone(timezone)
|
||||||
local_time = now.astimezone(tz)
|
local_time = now.astimezone(tz)
|
||||||
@ -24,12 +23,12 @@ class WorldTime(commands.Cog):
|
|||||||
# Handle invalid timezone
|
# Handle invalid timezone
|
||||||
await interaction.response.send_message(f"Unknown timezone: `{timezone}`\nTry using a timezone from the IANA Time Zone Database (e.g., 'America/New_York', 'Europe/London')", ephemeral=True)
|
await interaction.response.send_message(f"Unknown timezone: `{timezone}`\nTry using a timezone from the IANA Time Zone Database (e.g., 'America/New_York', 'Europe/London')", ephemeral=True)
|
||||||
else:
|
else:
|
||||||
# No timezone specified, show 5 random timezones
|
# no selected zone so displays fuckass zones :3
|
||||||
all_timezones = list(pytz.all_timezones)
|
all_timezones = list(pytz.all_timezones)
|
||||||
random_timezones = random.sample(all_timezones, 5)
|
random_timezones = random.sample(all_timezones, 5)
|
||||||
|
|
||||||
embed = discord.Embed(title="World Time", color=discord.Color.blue())
|
embed = discord.Embed(title="World Time", color=discord.Color.blue())
|
||||||
embed.description = "Here are 5 random timezones:"
|
embed.description = "Timezones"
|
||||||
|
|
||||||
for tz_name in random_timezones:
|
for tz_name in random_timezones:
|
||||||
tz = pytz.timezone(tz_name)
|
tz = pytz.timezone(tz_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user