Skip to content

Commit a346401

Browse files
Update command contexts and ensure data directory
* ✨ Make /rtfm user installable * 🙈 Ignore `.idea/` (JetBrains) * 🩹 Create `data` directory if it does not exist * 🐛 Use `discord.InteractionContextType.guild` instead of `guild_only=True`. * Format --------- Co-authored-by: Dorukyum <[email protected]>
1 parent 21995af commit a346401

File tree

9 files changed

+41
-29
lines changed

9 files changed

+41
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ __pycache__
33
*.log
44
data/
55
venv/
6+
.idea/

cogs/developer/__init__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ async def fetch_code_snippet(
250250
view=Delete(ctx.author),
251251
)
252252

253-
@discord.message_command(name="Link GitHub Issues", guild_only=True)
253+
@discord.message_command(
254+
name="Link GitHub Issues",
255+
contexts={discord.InteractionContextType.guild},
256+
)
254257
async def link_github_issues(
255258
self, ctx: discord.ApplicationContext, message: discord.Message
256259
):
@@ -278,8 +281,7 @@ async def link_github_issues(
278281
links[0] if len(links) == 1 else "\n".join(f"<{link}>" for link in links)
279282
)
280283

281-
@discord.slash_command()
282-
@discord.guild_only()
284+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
283285
@discord.default_permissions(manage_guild=True)
284286
@discord.option(
285287
"repo",
@@ -330,7 +332,17 @@ async def get_rtfm_results(self, target: str, query: str) -> list:
330332
)
331333
return results
332334

333-
@discord.command()
335+
@discord.command(
336+
integration_types={
337+
discord.IntegrationType.guild_install,
338+
discord.IntegrationType.user_install,
339+
},
340+
contexts={
341+
discord.InteractionContextType.bot_dm,
342+
discord.InteractionContextType.guild,
343+
discord.InteractionContextType.private_channel,
344+
},
345+
)
334346
@discord.option(
335347
"documentation",
336348
description="The documentation to search through.",

cogs/logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ async def on_guild_role_update(self, before: discord.Role, after: discord.Role):
268268
logs = discord.SlashCommandGroup(
269269
"logs",
270270
"Commands related to logs.",
271-
guild_only=True,
271+
contexts={discord.InteractionContextType.guild},
272272
default_member_permissions=discord.Permissions(manage_guild=True),
273273
)
274274

cogs/misc.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
class Miscellaneous(Cog):
1313
"""Miscellaneous commands."""
1414

15-
@discord.slash_command()
16-
@discord.guild_only()
15+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
1716
async def serverinfo(self, ctx: Context):
1817
"""View information/statistics about the server."""
1918
guild = ctx.guild
@@ -218,8 +217,7 @@ async def magic_8ball_yes_or_no(self, ctx: Context, question: str):
218217
await sleep(2)
219218
await ctx.respond(f"> {question}\n{answer}")
220219

221-
@discord.slash_command()
222-
@discord.guild_only()
220+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
223221
@discord.option("text", description="The text to check for in display names.")
224222
async def how_many(self, ctx: Context, *, text: str):
225223
"""Shows the amount of members that have the provided text in their display name."""

cogs/moderation.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
class Moderation(Cog):
88
"""Commands related to moderation."""
99

10-
@discord.slash_command()
11-
@discord.guild_only()
10+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
1211
@discord.default_permissions(ban_members=True)
1312
@discord.option(
1413
"members",
@@ -42,8 +41,7 @@ async def massban(
4241
)
4342
await ctx.respond(f"Banned **{count}** member{s(converted_members)}.")
4443

45-
@discord.slash_command()
46-
@discord.guild_only()
44+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
4745
@discord.default_permissions(manage_messages=True)
4846
@discord.option(
4947
"seconds",
@@ -62,8 +60,7 @@ async def slowmode(self, ctx: Context, seconds: int):
6260
else "Slowmode is now disabled."
6361
)
6462

65-
@discord.slash_command()
66-
@discord.guild_only()
63+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
6764
@discord.default_permissions(manage_roles=True)
6865
@discord.option(
6966
"permission",
@@ -105,8 +102,7 @@ async def lock(self, ctx: Context, permission: str, role: discord.Role | None, *
105102
f"The {permission} permission is now denied for {role.mention} in this channel."
106103
)
107104

108-
@discord.slash_command()
109-
@discord.guild_only()
105+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
110106
@discord.default_permissions(manage_roles=True)
111107
@discord.option(
112108
"permission",
@@ -165,7 +161,7 @@ async def purge_channel(self, ctx: Context, **kwargs):
165161
purge = discord.SlashCommandGroup(
166162
"purge",
167163
"Commands to purge messages.",
168-
guild_only=True,
164+
contexts={discord.InteractionContextType.guild},
169165
default_member_permissions=discord.Permissions(manage_messages=True),
170166
)
171167

cogs/server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Server(Cog):
1212
emoji = discord.SlashCommandGroup(
1313
"emoji",
1414
"Commands related to emojis.",
15-
guild_only=True,
15+
contexts={discord.InteractionContextType.guild},
1616
default_member_permissions=discord.Permissions(manage_guild=True),
1717
)
1818

@@ -59,7 +59,7 @@ async def emoji_delete(
5959
suggestions = discord.SlashCommandGroup(
6060
"suggestions",
6161
"Commands related to member suggestions.",
62-
guild_only=True,
62+
contexts={discord.InteractionContextType.guild},
6363
default_member_permissions=discord.Permissions(manage_guild=True),
6464
)
6565

@@ -89,8 +89,7 @@ async def suggestions_disable(self, ctx: Context):
8989
)
9090
await ctx.respond("Member suggestions are already disabled for this server.")
9191

92-
@discord.slash_command()
93-
@discord.guild_only()
92+
@discord.slash_command(contexts={discord.InteractionContextType.guild})
9493
@discord.option("suggestion", description="The suggestion.")
9594
async def suggest(self, ctx: Context, *, suggestion: str):
9695
"""Make a suggestion for the server. This will be sent to the channel set by the server managers."""

cogs/tags.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
class Tags(Cog):
1010
"""Commands related to tags."""
1111

12-
tag = discord.SlashCommandGroup("tag", "Commands related to tags.", guild_only=True)
12+
tag = discord.SlashCommandGroup(
13+
"tag",
14+
"Commands related to tags.",
15+
contexts={discord.InteractionContextType.guild},
16+
)
1317

1418
async def get_tag_names(self, ctx: discord.AutocompleteContext) -> List[str]:
1519
assert ctx.interaction.guild_id

cogs/warnings.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,25 @@ def format_warning(self, warn: WarnModel) -> str:
7575
f"By **{f'{mod.name} ({mod.mention})' if mod else f'Unknown User (<@{warn.mod_id}>)'}**"
7676
)
7777

78-
@discord.slash_command(name="warn")
79-
@discord.guild_only()
78+
@discord.slash_command(name="warn", contexts={discord.InteractionContextType.guild})
8079
@discord.default_permissions(manage_messages=True)
8180
@discord.option("member", description="The member to warn.")
8281
@discord.option("reason", description="The reason of the warning.")
8382
async def warn_slash(self, ctx: Context, member: discord.Member, *, reason: str):
8483
"""Warn a member."""
8584
await warn(ctx.interaction, member, reason)
8685

87-
@discord.user_command(name="Warn Member")
88-
@discord.guild_only()
86+
@discord.user_command(name="Warn Member", contexts={discord.InteractionContextType.guild})
8987
@discord.default_permissions(manage_messages=True)
9088
async def warn_member(self, ctx: Context, member: discord.Member):
9189
"""Warn a member."""
9290
await ctx.send_modal(WarnModal(member, self.bot.get_cog("Logs")))
9391

9492
warning = discord.SlashCommandGroup(
95-
"warning", "Commands related to warnings.", guild_only=True, default_member_permissions=discord.Permissions(manage_messages=True)
93+
"warning",
94+
"Commands related to warnings.",
95+
contexts={discord.InteractionContextType.guild},
96+
default_member_permissions=discord.Permissions(manage_messages=True),
9697
)
9798

9899
@warning.command()

core/bot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os import environ, getenv
1+
from os import environ, getenv, makedirs
22
from traceback import format_exception
33

44
import discord
@@ -29,6 +29,7 @@ def __init__(self) -> None:
2929
self.cache: dict[str, dict] = {"example_list": {}}
3030

3131
async def setup_tortoise(self) -> None:
32+
makedirs("data", exist_ok=True)
3233
await Tortoise.init(
3334
db_url="sqlite://data/database.db", modules={"models": ["core.models"]}
3435
)

0 commit comments

Comments
 (0)