Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit 2caac9e

Browse files
committed
Set a few bot slash commands as server-only
This will help prevent unexpected errors due to lack of guild data by running commands in isobot DMs, for commands that require information about guilds (servers).
1 parent fee1936 commit 2caac9e

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

cogs/afk.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self, bot):
2222
name="set",
2323
description="Sets your AFK status with a custom response"
2424
)
25+
@commands.guild_only()
2526
@option(name="response", description="What do you want your AFK response to be?", type=str, default="I'm AFK")
2627
async def afk_set(self, ctx: ApplicationContext, response: str="I'm AFK"):
2728
presence.add_afk(ctx.guild.id, ctx.user.id, response)
@@ -32,6 +33,7 @@ async def afk_set(self, ctx: ApplicationContext, response: str="I'm AFK"):
3233
name="remove",
3334
description="Removes your AFK status"
3435
)
36+
@commands.guild_only()
3537
async def afk_remove(self, ctx: ApplicationContext):
3638
status = presence.remove_afk(ctx.guild.id, ctx.author.id)
3739
if status == 0: return await ctx.respond(f"Alright {ctx.author.mention}, I've removed your AFK.")
@@ -41,6 +43,7 @@ async def afk_remove(self, ctx: ApplicationContext):
4143
name="mod_remove",
4244
description="Removes an AFK status for someone else"
4345
)
46+
@commands.guild_only()
4447
@option(name="user", description="Whose AFK status do you want to remove?", type=discord.User)
4548
async def afk_mod_remove(self, ctx: ApplicationContext, user:discord.User):
4649
if not ctx.author.guild_permissions.manage_messages: return await ctx.respond("You don't have the required permissions to use this.", ephemeral=True)

cogs/automod.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self, bot):
2222
name="config",
2323
description="Shows the current automod configuration for your server"
2424
)
25+
@commands.guild_only()
2526
async def automod_config(self, ctx: ApplicationContext):
2627
loaded_config = automod.fetch_config(ctx.guild.id)
2728
localembed = discord.Embed(title=f"{ctx.guild.name}\'s automod configuration", description="Use the `/automod_set` command to change your server's automod configuration.", color=color)
@@ -36,6 +37,7 @@ async def automod_config(self, ctx: ApplicationContext):
3637
name="swearfilter",
3738
description="Turn on or off automod's swear-filter in your server"
3839
)
40+
@commands.guild_only()
3941
@option(name="toggle", description="Do you want to turn it on or off?", type=bool)
4042
async def automod_swearfilter(self, ctx: ApplicationContext, toggle: bool):
4143
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -48,6 +50,7 @@ async def automod_swearfilter(self, ctx: ApplicationContext, toggle: bool):
4850
name="use_default_keywords",
4951
description="Choose whether or not you want to use the default keywords for automod's swear-filter"
5052
)
53+
@commands.guild_only()
5154
@option(name="toggle", description="Do you want to turn it on or off?", type=bool)
5255
async def automod_use_default_keywords(self, ctx: ApplicationContext, toggle: bool):
5356
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -60,6 +63,7 @@ async def automod_use_default_keywords(self, ctx: ApplicationContext, toggle: bo
6063
name="view_custom_keywords",
6164
description="Shows a list of the custom automod swear-filter keywords set for your server",
6265
)
66+
@commands.guild_only()
6367
async def automod_view_custom_keywords(self, ctx: ApplicationContext):
6468
loaded_config = automod.fetch_config(ctx.guild.id)
6569
out = ""
@@ -77,6 +81,7 @@ async def automod_view_custom_keywords(self, ctx: ApplicationContext):
7781
name="add_custom_keyword",
7882
description="Adds a custom keyword to your server's swear-filter"
7983
)
84+
@commands.guild_only()
8085
@option(name="keyword", description="What keyword do you want to add?", type=str)
8186
async def automod_add_custom_keyword(self, ctx: ApplicationContext, keyword:str):
8287
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -91,6 +96,7 @@ async def automod_add_custom_keyword(self, ctx: ApplicationContext, keyword:str)
9196
name="remove_custom_keyword",
9297
description="Removes a custom keyword (matching its id) from your server's swear-filter"
9398
)
99+
@commands.guild_only()
94100
@option(name="id", description="What's the id of the keyword to remove (can be found through /automod_view_custom_keywords", type=int)
95101
async def automod_remove_custom_keyword(self, ctx: ApplicationContext, id: int):
96102
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -104,6 +110,7 @@ async def automod_remove_custom_keyword(self, ctx: ApplicationContext, id: int):
104110
name="linkblocker",
105111
description="Turn on or off automod's link blocker in your server"
106112
)
113+
@commands.guild_only()
107114
@option(name="toggle", description="Do you want to turn it on or off?", type=bool)
108115
async def automod_linkblocker(self, ctx: ApplicationContext, toggle: bool):
109116
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -116,6 +123,7 @@ async def automod_linkblocker(self, ctx: ApplicationContext, toggle: bool):
116123
name="linkblocker_only_whitelisted",
117124
description="Only allows whitelisted links in the server and blocks all other links"
118125
)
126+
@commands.guild_only()
119127
@option(name="toggle", description="Do you want to turn it on or off?", type=bool)
120128
async def automod_linkblocker_only_whitelisted_links(self, ctx: ApplicationContext, toggle: bool):
121129
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -128,6 +136,7 @@ async def automod_linkblocker_only_whitelisted_links(self, ctx: ApplicationConte
128136
name="linkblocker_add_whitelist",
129137
description="Adds a link to your server link blocker's whitelist."
130138
)
139+
@commands.guild_only()
131140
@option(name="link", description="The link that you want to add (must be in form of https://{url})", type=str)
132141
async def automod_linkblocker_add_whitelist(self, ctx: ApplicationContext, link: str):
133142
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -141,6 +150,7 @@ async def automod_linkblocker_add_whitelist(self, ctx: ApplicationContext, link:
141150
name="linkblocker_add_blacklist",
142151
description="Adds a link to your server link blocker's blacklist."
143152
)
153+
@commands.guild_only()
144154
@option(name="link", description="The link that you want to add (must be in form of https://{url})", type=str)
145155
async def automod_linkblocker_add_blacklist(self, ctx: ApplicationContext, link: str):
146156
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -154,6 +164,7 @@ async def automod_linkblocker_add_blacklist(self, ctx: ApplicationContext, link:
154164
name="linkblocker_view_whitelisted",
155165
description="Shows a list of the whitelisted links set for this server",
156166
)
167+
@commands.guild_only()
157168
async def automod_view_custom_keywords(self, ctx: ApplicationContext):
158169
loaded_config = automod.fetch_config(ctx.guild.id)
159170
out = ""
@@ -171,6 +182,7 @@ async def automod_view_custom_keywords(self, ctx: ApplicationContext):
171182
name="linkblocker_view_blacklisted",
172183
description="Shows a list of the blacklisted links set for this server",
173184
)
185+
@commands.guild_only()
174186
async def automod_view_custom_keywords(self, ctx: ApplicationContext):
175187
loaded_config = automod.fetch_config(ctx.guild.id)
176188
out = ""
@@ -188,6 +200,7 @@ async def automod_view_custom_keywords(self, ctx: ApplicationContext):
188200
name="linkblocker_remove_blacklist",
189201
description="Removes a blacklisted link (matching its id) from this server's link blocker"
190202
)
203+
@commands.guild_only()
191204
@option(name="id", description="What's the id of the link to remove? (can be found through /automod_view_blacklisted_links", type=int)
192205
async def automod_linkblocker_remove_blacklist(self, ctx: ApplicationContext, id: int):
193206
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)
@@ -200,6 +213,7 @@ async def automod_linkblocker_remove_blacklist(self, ctx: ApplicationContext, id
200213
name="linkblocker_remove_whitelist",
201214
description="Removes a whitelisted link (matching its id) from this server's link blocker"
202215
)
216+
@commands.guild_only()
203217
@option(name="id", description="What's the id of the link to remove? (can be found through /automod_view_whitelisted_links", type=int)
204218
async def automod_linkblocker_remove_whitelist(self, ctx: ApplicationContext, id: int):
205219
if not ctx.author.guild_permissions.administrator: return await ctx.respond("You cannot use this command. If you think this is a mistake, please contact your server owner/administrator.", ephemeral=True)

cogs/moderation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, bot):
1717
name='kick',
1818
description='Kicks a member from this server.'
1919
)
20+
@commands.guild_only()
2021
@option(name="user", description="Who do you want to kick?", type=discord.User)
2122
@option(name="reason", description="Why do you want to kick the user?", type=str, default=None)
2223
@commands.cooldown(1, 3, commands.BucketType.user)
@@ -31,6 +32,7 @@ async def kick(self, ctx: ApplicationContext, user, reason=None):
3132
name='ban',
3233
description='Bans a member from this server.'
3334
)
35+
@commands.guild_only()
3436
@option(name="user", description="Who do you want to ban?", type=discord.User)
3537
@option(name="reason", description="Why you want to ban the user?", type=str, default=None)
3638
@commands.cooldown(1, 3, commands.BucketType.user)
@@ -47,6 +49,7 @@ async def ban(self, ctx: ApplicationContext, user, reason=None):
4749
name="warn",
4850
description="Warns the specified user, with a specific reason."
4951
)
52+
@commands.guild_only()
5053
@option(name="user", description="Who do you want to warn?", type=discord.Member)
5154
@option(name="reason", description="The reason why you are warning the user", type=str)
5255
async def warn(self, ctx: ApplicationContext, user: discord.Member, reason: str):
@@ -74,6 +77,7 @@ async def warn(self, ctx: ApplicationContext, user: discord.Member, reason: str)
7477
name="clear_all_warnings",
7578
description="Clears all the warnings from the specified user."
7679
)
80+
@commands.guild_only()
7781
@option(name="user", description="The user whose warnings you want to clear.", type=discord.Member)
7882
async def clear_all_warning(self, ctx: ApplicationContext, user: discord.Member):
7983
"""Clears all the warnings from the specified user."""
@@ -94,6 +98,7 @@ async def clear_all_warning(self, ctx: ApplicationContext, user: discord.Member)
9498
name="show_warnings",
9599
description="See all the server warnings for a specific user."
96100
)
101+
@commands.guild_only()
97102
@option(name="user", description="The user whose warnings you want to view.", type=discord.Member, default=None)
98103
async def show_warnings(self, ctx: ApplicationContext, user: discord.Member = None):
99104
"""See all the server warnings for a specific user."""

cogs/serverconfig.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, bot):
2525
name="autorole",
2626
description="Set a role to provide to all newly-joined members of the server."
2727
)
28+
@commands.guild_only()
2829
@option(name="role", description="The role that you want to automatically give to all new members.", type=discord.Role, default=None)
2930
async def autorole(self, ctx: ApplicationContext, role: discord.Role = None):
3031
"""Set a role to provide to all newly-joined members of the server."""
@@ -50,6 +51,7 @@ async def autorole(self, ctx: ApplicationContext, role: discord.Role = None):
5051
name="levelup_override_channel",
5152
description="Set a server channel to send level-up messages to, instead of DMs."
5253
)
54+
@commands.guild_only()
5355
@option(name="channel", description="The channel in which you want level-up messages to be sent.", type=discord.TextChannel, default=None)
5456
async def autorole(self, ctx: ApplicationContext, channel: discord.TextChannel = None):
5557
"""Set a role to provide to all newly-joined members of the server."""
@@ -76,6 +78,7 @@ async def autorole(self, ctx: ApplicationContext, channel: discord.TextChannel =
7678
name="enable_verification",
7779
description="Enable new member verification for this server."
7880
)
81+
@commands.guild_only()
7982
@option(name="verified_role", description="The role to provide to all verified members.", type=discord.Role)
8083
async def enable_verification(self, ctx: ApplicationContext, verified_role: discord.Role):
8184
"""Enable new user verification for this server."""
@@ -93,6 +96,7 @@ async def enable_verification(self, ctx: ApplicationContext, verified_role: disc
9396
name="disable_verification",
9497
description="Disable new member verification for this server."
9598
)
99+
@commands.guild_only()
96100
async def disable_verification(self, ctx: ApplicationContext):
97101
"""Disable new member verification for this server."""
98102
if not ctx.author.guild_permissions.administrator:

cogs/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ async def embedbuilder(self, ctx: ApplicationContext, title: str, description: s
100100
name='whoami',
101101
description='Shows information on a user.'
102102
)
103+
@commands.guild_only()
103104
@option(name="user", description="Who do you want to know about?", type=discord.User, default=None)
104105
async def whoami(self, ctx: ApplicationContext, user: discord.User=None):
105106
"""Shows information on a user."""
@@ -301,6 +302,7 @@ async def vote(self, ctx: ApplicationContext):
301302
name="nuke",
302303
description="Completely wipes a text channel in the server."
303304
)
305+
@commands.guild_only()
304306
@option(name="channel", description="The channel you want to nuke.", type=discord.TextChannel)
305307
async def nuke(self, ctx: ApplicationContext, channel: discord.TextChannel):
306308
"""Completely wipes a text channel in the server."""

0 commit comments

Comments
 (0)