【发布时间】:2022-01-19 19:37:33
【问题描述】:
@client.command(aliases=['tempmute'])
@commands.has_permissions(manage_messages=True)
async def tmute(ctx, member: discord.Member=None, time=None, *, reason=None):
if not member:
await ctx.send("You must mention a member to mute!")
elif not time:
await ctx.send("You must mention a time!")
else:
if not reason:
reason="No reason given"
try:
seconds = time[:-1]
duration = time[-1]
if duration == "s":
seconds = seconds * 1
elif duration == "m":
seconds = seconds * 60
elif duration == "h":
seconds = seconds * 60 * 60
elif duration == "d":
seconds = seconds * 86400
else:
await ctx.send("Invalid duration input")
return
except Exception as e:
print(e)
await ctx.send("Invalid time input")
return
guild = ctx.guild
Muted = discord.utils.get(guild.roles, name="Muted")
if not Muted:
Muted = await guild.create_role(name="Muted")
for channel in guild.channels:
await channel.set_permissions(mutedRole, speak=False, send_messages=False, read_message_history=True, read_messages=False)
await member.add_roles(Muted, reason=reason)
muted_embed = discord.Embed(title="Muted a user", description=f"{member.mention} Was muted by {ctx.author.mention} for {reason} to {time}")
await ctx.send(embed=muted_embed)
await asyncio.sleep(seconds)
await member.remove_roles(Muted)
unmute_embed = discord.Embed(title="Mute over!", description=f'{ctx.author.mention} muted to {member.mention} for {reason} is over after {time}')
await ctx.send(embed=unmute_embed)
我没有收到任何错误,代码工作正常,直到我到达命令的时间操作部分,所以 !mute @Test 1d testreason 代码工作正常,直到我到达 1d 部分然后停止工作,我有不知道为什么,请帮忙。
【问题讨论】:
标签: python discord discord.py