Skip to content

Commit e83677d

Browse files
committed
Fix for commands executed in DMs
1 parent 7d6d8ef commit e83677d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

bot.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ async def on_slash_command(interaction: ApplicationCommandInteraction) -> None:
142142
The code in this event is executed every time a slash command has been *successfully* executed
143143
:param interaction: The slash command that has been executed.
144144
"""
145-
print(
146-
f"Executed {interaction.data.name} command in {interaction.guild.name} (ID: {interaction.guild.id}) by {interaction.author} (ID: {interaction.author.id})")
145+
146+
if interaction.guild is not None:
147+
print(
148+
f"Executed {interaction.data.name} slash command in {interaction.guild.name} (ID: {interaction.guild.id}) by {interaction.author} (ID: {interaction.author.id})")
149+
else:
150+
print(f"Executed {interaction.data.name} slash command by {interaction.author} (ID: {interaction.author.id}) in DMs")
147151

148152

149153
@bot.event
@@ -215,8 +219,11 @@ async def on_command_completion(context: Context) -> None:
215219
full_command_name = context.command.qualified_name
216220
split = full_command_name.split(" ")
217221
executed_command = str(split[0])
218-
print(
219-
f"Executed {executed_command} command in {context.guild.name} (ID: {context.message.guild.id}) by {context.message.author} (ID: {context.message.author.id})")
222+
if context.guild is not None:
223+
print(
224+
f"Executed {executed_command} command in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id})")
225+
else:
226+
print(f"Executed {executed_command} command by {context.author} (ID: {context.author.id}) in DMs")
220227

221228

222229
@bot.event

0 commit comments

Comments
 (0)