【发布时间】:2020-11-21 05:52:37
【问题描述】:
对 Discordpy 审核命令有点陌生,想知道为什么此代码不起作用, 因为我在尝试运行它时没有错误。它应该根据单位临时将用户静音一段时间,如果没有创建静音角色,则创建一个。
@commands.command()
async def mute(self , ctx, user : discord.Member, duration = 0,*, unit = None):
guild = ctx.guild
for role in guild.roles:
if role.name =="Muted":
await member.add_roles(role)
await ctx.send("{} Has been muted by {} for {duration}{unit} " .format(member.mention,ctx.author.mention))
return
overwrite = discord.PermissionsOverwrite(send_messages=False)
newRole = await guild.create_role(name="Muted")
for channel in guild.text_channels:
await channel.set_permissions(newRole,overwrite=overwrite)
await member.add_roles(newRole)
await ctx.send("{} Has been muted by {} for {duration}{unit} " .format(member.mention,ctx.author.mention))
if unit == "s":
wait = 1 * duration
await asyncio.sleep(wait)
elif unit == "m":
wait = 60 * duration
await asyncio.sleep(wait)
await user.remove_roles(roleobject)
await ctx.send(f":white_check_mark: {user} was unmuted")
```
【问题讨论】:
标签: discord.py