python - discord.py - “member” 参数总是返回一个字符串,即使使用转换器 discord.User
问题描述
正如标题中所说,我在 Moderation cog 中有一个静音函数,它接受一个成员参数,但是即使使用转换器,“member”最终还是一个看起来像“user#0000”的字符串。Moderation 类的所有其他方法都将成员作为对象。是什么原因造成的?
这是静音():
@commands.command()
@commands.guild_only()
@commands.has_permissions(kick_members=True)
async def mute(self, ctx, member: discord.Member, *, reason="unspecified"):
""""""
try:
await member.add_roles(self.get_role(ctx.guild.id, "muted_role"))
await member.remove_roles(self.get_role(ctx.guild.id, "default_role"))
except Exception as e:
await ctx.send(f"**Error**: `{e}`")
else:
await ctx.send(f"{member.id} was muted.")
if not self.get_channel(ctx.guild.id, "log_channel"):
await ctx.send(self.no_log_chan)
return
await self.get_channel(ctx.guild.id, "log_channel").send(
self.get_embed(
"__MUTE__",
ctx.message.author,
"#00FF00",
f"{member.id} was muted by {ctx.message.author} \nReason : *{reason}*",
datetime.now().strftime("%H:%M:%S"),
ctx.message.author.avatar_url,
)
)
这是我的 kick() 方法,效果很好:
@commands.command()
@commands.guild_only()
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, member: discord.User, *, reason="unspecified"):
""""""
try:
await ctx.guild.kick(member)
except Exception as e:
await ctx.send(f"**Error**: `{e}`")
else:
await ctx.send(f"{member.id} was kicked.")
if not self.get_channel(ctx.guild.id, "log_channel"):
await ctx.send(self.no_log_chan)
return
await self.get_channel(ctx.guild.id, "log_channel").send(
self.get_embed(
"__KICK__",
ctx.message.author,
"#00FF00",
f"{member.id} was kicked from the server by {ctx.message.author} \nReason : *{reason}*",
datetime.now().strftime("%H:%M:%S"),
member.avatar_url,
)
)
解决方案
直到最后一个版本,它的工作方式是这样的:
async def Function(ctx, member:discord.User):
希望它有用。
推荐阅读
- c++ - 初始化私有静态复合 constexpr 值
- keras - Keras fit_generator raise 你必须在使用它之前编译你的模型错误
- java - 删除 int 数组中的前导零
- sql - 如何在where子句中添加case语句
- bash - 使用 f=$(cd dir | ls -t | head) 获取目录中最新文件的路径不尊重“dir”
- html - 如何使我的六边形网格适合所有设备?
- javascript - 包括会话时,我不能使用 $_FILES
- sql - Rank 函数给出不正确的排名
- java - DateTimeFormatter 的工作速度极慢
- asp.net - Asp.net 文本框并排显示