Skip to content

Instantly share code, notes, and snippets.

@Wolfhound905
Created December 17, 2021 04:32
Show Gist options
  • Save Wolfhound905/662379da5963c83b41b29db054db4d54 to your computer and use it in GitHub Desktop.
Save Wolfhound905/662379da5963c83b41b29db054db4d54 to your computer and use it in GitHub Desktop.
What the command is
@slash_command("create_event", "Create a scheduled event", scopes=[902005056872775760])
@slash_option("name", "The name of the event", required=True, opt_type=OptionTypes.STRING)
@slash_option("start_time", "YEAR/MONTH/DAY The start time of the event", required=True, opt_type=OptionTypes.STRING)
@slash_option(
"event_type",
"The type of the event",
required=True,
opt_type=OptionTypes.INTEGER,
choices=[
SlashCommandChoice("Stage", ScheduledEventEntityType.STAGE_INSTANCE),
SlashCommandChoice("Voice", ScheduledEventEntityType.VOICE),
SlashCommandChoice("External", ScheduledEventEntityType.EXTERNAL),
],
)
@slash_option(
"channel", "Either Voice or Stage. The channel to send the event to", required=False, opt_type=OptionTypes.CHANNEL
)
@slash_option("end_time", "YEAR/MONTH/DAY The end time of the event", required=False, opt_type=OptionTypes.STRING)
@slash_option("external_location", "ONLY IF TYPE EXTERNAL", required=False, opt_type=OptionTypes.STRING)
@slash_option("description", "The description of the event", required=False, opt_type=OptionTypes.STRING)
async def create_event(
ctx: InteractionContext,
name: str,
start_time: str,
event_type: ScheduledEventEntityType,
channel: Union["VoiceChannel", "StageInstance"] = MISSING,
description: str = MISSING,
end_time: str = MISSING,
external_location: str = MISSING,
):
"""Create a scheduled event"""
start_time = Timestamp.fromdatetime(datetime.strptime(start_time, "%Y/%m/%d"))
if end_time:
end_time = Timestamp.fromdatetime(datetime.strptime(end_time, "%Y/%m/%d"))
event: ScheduledEvent = await ctx.guild.create_scheduled_event(
name=name,
description=description,
scheduled_start_time=start_time,
scheduled_end_time=end_time,
entity_type=event_type,
entity_metadata=dict(location=external_location),
channel_id=channel.id,
)
embed = Embed(title=f"Created event {event.name}", description=f"{event.description}")
embed.add_field(
name="Info",
value=(
f"""Starts: {event.scheduled_start_time.format(TimestampStyles.RelativeTime)}
Ends: {event.scheduled_end_time.format(TimestampStyles.RelativeTime)}"""
),
)
await ctx.send(embed=embed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment