Skip to content

Commit a15e068

Browse files
fix(commands): fix moderator user info command (#409)
1 parent f26a6fc commit a15e068

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/discord_bot/cogs/moderator_commands.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,19 @@ async def sync_command(
9999
ctx : discord.ApplicationContext
100100
Request message context.
101101
"""
102+
await ctx.defer(ephemeral=True)
103+
102104
now = time.time()
103-
msg = await ctx.respond("Syncing commands...", ephemeral=True)
104105
await self.bot.sync_commands(
105106
force=True,
106107
guild_ids=[ctx.guild_id],
107108
)
108109
duration = int(time.time() - now)
109-
await msg.edit(content="""Synced commands!
110+
await ctx.respond("""Synced commands!
110111
111112
Sync duration: {}s
112113
Commands not showing up? Try restarting discord or clearing cache.
113-
""".format(duration))
114+
""".format(duration), ephemeral=True)
114115

115116
@mod_commands.command(
116117
name="user-info",
@@ -135,47 +136,48 @@ async def user_info_command(
135136
user : discord.User
136137
User to get information about.
137138
"""
138-
user = user or ctx.author
139+
target_user = user or ctx.author
139140
embed = discord.Embed(
140141
fields=[
141-
discord.EmbedField(name="ID", value=str(user.id), inline=False), # User ID
142+
discord.EmbedField(name="ID", value=str(target_user.id), inline=False), # User ID
142143
discord.EmbedField(
143144
name="Joined Discord at",
144-
value=f'{discord.utils.format_dt(user.created_at, "R")}\n'
145-
f'{discord.utils.format_dt(user.created_at, "F")}',
145+
value=f'{discord.utils.format_dt(target_user.created_at, "R")}\n'
146+
f'{discord.utils.format_dt(target_user.created_at, "F")}',
146147
inline=False,
147148
), # When the user's account was created
148149
],
149150
)
150-
embed.set_author(name=user.name)
151-
embed.set_thumbnail(url=user.display_avatar.url)
151+
embed.set_author(name=target_user.name)
152+
embed.set_thumbnail(url=target_user.display_avatar.url)
152153

153-
embed.colour = user.color if user.color.value else colors['white']
154+
embed.colour = target_user.color if target_user.color.value else colors['white']
154155

155156
with self.bot.db as db:
156-
user_data = db.get('discord_users', {}).get(str(user.id))
157-
if user_data and user_data.get('github_username'):
157+
users_table = db.table('discord_users')
158+
user_doc = users_table.get(self.bot.db.query().id == str(target_user.id))
159+
if user_doc and user_doc.get('github_username'):
158160
embed.add_field(
159161
name="GitHub",
160-
value=f"[{user_data['github_username']}](https://github.com/{user_data['github_username']})",
162+
value=f"[{user_doc['github_username']}](https://github.com/{user_doc['github_username']})",
161163
inline=False,
162164
)
163165

164-
if isinstance(user, discord.User): # Checks if the user in the server
166+
if isinstance(target_user, discord.User): # Checks if the user in the server
165167
embed.set_footer(text="This user is not in this server.")
166168
await ctx.respond(embeds=[embed])
167169
return
168170

169171
# We end up here if the user is a discord.Member object
170172
embed.add_field(
171173
name="Joined Server at",
172-
value=f'{discord.utils.format_dt(user.joined_at, "R")}\n'
173-
f'{discord.utils.format_dt(user.joined_at, "F")}',
174+
value=f'{discord.utils.format_dt(target_user.joined_at, "R")}\n'
175+
f'{discord.utils.format_dt(target_user.joined_at, "F")}',
174176
inline=False,
175177
) # When the user joined the server
176178

177179
# get User Roles
178-
roles = [role.name for role in user.roles]
180+
roles = [role.name for role in target_user.roles]
179181
roles.pop(0) # remove @everyone role
180182
embed.add_field(
181183
name="Server Roles",
@@ -185,21 +187,21 @@ async def user_info_command(
185187

186188
# get User Status, such as Server Owner, Server Moderator, Server Admin, etc.
187189
user_status = []
188-
if user.guild.owner_id == user.id:
190+
if target_user.guild.owner_id == target_user.id:
189191
user_status.append("Server Owner")
190-
if user.guild_permissions.administrator:
192+
if target_user.guild_permissions.administrator:
191193
user_status.append("Server Admin")
192-
if user.guild_permissions.manage_guild:
194+
if target_user.guild_permissions.manage_guild:
193195
user_status.append("Server Moderator")
194196
embed.add_field(
195197
name="User Status",
196198
value='\n'.join(user_status),
197199
inline=False,
198200
)
199201

200-
if user.premium_since: # If the user is boosting the server
201-
boosting_value = (f'{discord.utils.format_dt(user.premium_since, "R")}\n'
202-
f'{discord.utils.format_dt(user.premium_since, "F")}')
202+
if target_user.premium_since: # If the user is boosting the server
203+
boosting_value = (f'{discord.utils.format_dt(target_user.premium_since, "R")}\n'
204+
f'{discord.utils.format_dt(target_user.premium_since, "F")}')
203205
else:
204206
boosting_value = "Not boosting"
205207
embed.add_field(

0 commit comments

Comments
 (0)