2024-05-05 14:46:49 +05:30
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import discord
|
|
|
|
from discord.ext import commands
|
|
|
|
|
2024-05-05 15:00:53 +05:30
|
|
|
|
|
|
|
def create_discord_event(
|
|
|
|
bot_token,
|
|
|
|
guild_id,
|
|
|
|
EVENT_NAME,
|
|
|
|
EVENT_DESCRIPTION,
|
|
|
|
EVENT_LOCATION,
|
|
|
|
EVENT_DATE,
|
|
|
|
EVENT_START_TIME,
|
|
|
|
EVENT_END_TIME,
|
2024-05-05 14:46:49 +05:30
|
|
|
):
|
|
|
|
|
2024-05-13 14:01:46 +05:30
|
|
|
bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())
|
2024-05-05 14:46:49 +05:30
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
|
|
|
|
|
|
|
# Convert the date string to a datetime object
|
|
|
|
date_object = datetime.strptime(EVENT_DATE, "%Y-%m-%d")
|
|
|
|
|
|
|
|
# Convert the time string to a datetime object
|
|
|
|
start_time_object = datetime.strptime(EVENT_START_TIME, "%H:%M")
|
|
|
|
end_time_object = datetime.strptime(EVENT_END_TIME, "%H:%M")
|
|
|
|
|
|
|
|
# Combine the date and time objects
|
2024-05-05 15:00:53 +05:30
|
|
|
st = date_object.replace(
|
|
|
|
hour=start_time_object.hour, minute=start_time_object.minute
|
|
|
|
).astimezone()
|
|
|
|
et = date_object.replace(
|
|
|
|
hour=end_time_object.hour, minute=end_time_object.minute
|
|
|
|
).astimezone()
|
2024-05-05 14:46:49 +05:30
|
|
|
|
|
|
|
gg = bot.get_guild(guild_id)
|
|
|
|
|
|
|
|
try:
|
|
|
|
event = await gg.create_scheduled_event(
|
2024-05-05 15:00:53 +05:30
|
|
|
name=EVENT_NAME,
|
|
|
|
entity_type=discord.EntityType.external,
|
2024-05-05 14:46:49 +05:30
|
|
|
description=EVENT_DESCRIPTION,
|
|
|
|
start_time=st,
|
2024-05-05 15:00:53 +05:30
|
|
|
end_time=et,
|
|
|
|
location=EVENT_LOCATION,
|
2024-05-05 14:46:49 +05:30
|
|
|
privacy_level=discord.PrivacyLevel.guild_only,
|
2024-05-05 15:00:53 +05:30
|
|
|
)
|
2024-05-13 14:01:46 +05:30
|
|
|
print("Discord Event created: ", event.url)
|
2024-05-05 15:00:53 +05:30
|
|
|
|
2024-05-05 14:46:49 +05:30
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2024-05-05 15:00:53 +05:30
|
|
|
|
2024-05-05 14:46:49 +05:30
|
|
|
await bot.close()
|
2024-05-05 15:00:53 +05:30
|
|
|
|
2024-05-05 14:46:49 +05:30
|
|
|
# Run the bot
|
|
|
|
bot.run(bot_token)
|