【发布时间】:2021-03-28 15:13:46
【问题描述】:
我的 discord.py 机器人有这个代码,用于我的 tempmute 命令:
@bot.command()
async def tempmute(ctx, member: discord.Member, time: int, d, *, reason=None):
guild = ctx.guild
mutedRole = discord.utils.get(guild.roles, name="Muted")
if not mutedRole:
mutedRole = await guild.create_role(name="Muted")
for channel in guild.channels:
await channel.set_permissions(mutedRole, speak=False, send_messages=False)
for role in guild.roles:
if role.name == "Muted":
await member.add_roles(role)
embed = discord.Embed(title="TempMuted!", description=f"{member.mention} has been tempmuted.", colour=discord.Colour.red())
embed.add_field(name="Reason:", value=reason, inline=False)
embed.add_field(name="Time for the mute:", value=f"{time}{d}", inline=False)
await ctx.send(embed=embed)
if d == "s":
await asyncio.sleep(time)
if d == "m":
await asyncio.sleep(time*60)
if d == "h":
await asyncio.sleep(time*60*60)
if d == "d":
await asyncio.sleep(time*60*60*24)
await member.remove_roles(role)
embed = discord.Embed(title="Unmute (temp mute expired) ", description=f"Unmuted -{member.mention} ", colour=discord.Colour.light_gray())
await ctx.send(embed=embed)
return
但是,在使用命令时,如果我想要 10 分钟静音,则必须这样输入:“!tempmute @user 10 m”。注意它是“10 m”。我将如何使它“10m”可以工作(没有空格)。所以“!tempmute @user 10m”?如果用户此时写入时没有空格,则会出现错误“discord.ext.commands.errors.BadArgument: Converting to "int" failed for parameter "time"。”发生,可能是因为它无法识别末尾带有字母的数字。谢谢
【问题讨论】:
标签: discord.py