-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinvite_link.py
More file actions
49 lines (36 loc) · 1.59 KB
/
invite_link.py
File metadata and controls
49 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Contains cog classes for any invite link display interactions."""
from typing import TYPE_CHECKING
import discord
from config import settings
from utils import TeXBotBaseCog
if TYPE_CHECKING:
from collections.abc import Sequence
from utils import TeXBotApplicationContext
__all__: "Sequence[str]" = ("InviteLinkCommandCog",)
class InviteLinkCommandCog(TeXBotBaseCog):
"""Cog class that defines the "/invite-link" command and its call-back method."""
@discord.slash_command(
name="invite-link", description="Display the invite link to this server."
)
async def invite_link(self, ctx: "TeXBotApplicationContext") -> None:
"""Definition & callback response of the "invite_link" command."""
discord_invite_url: str | None = settings["CUSTOM_DISCORD_INVITE_URL"]
if not discord_invite_url:
invite_destination_channel: discord.TextChannel | None = discord.utils.get(
ctx.bot.main_guild.text_channels, name="welcome"
)
if invite_destination_channel is None:
invite_destination_channel = await ctx.bot.rules_channel
discord_invite_url = (
await invite_destination_channel.create_invite(
reason=f'{ctx.user} used TeX Bot slash-command: "/invite-link"',
max_age=21600,
)
).url
await ctx.respond(
(
f"Invite your friends to the {self.bot.group_short_name} Discord server: "
f"{discord_invite_url}"
),
ephemeral=False,
)