【发布时间】:2021-09-29 23:57:15
【问题描述】:
@client.command(description="Mutes the specified user.")
@commands.has_permissions(manage_messages=True)
async def mute(ctx, member: discord.Member, time=None, *, reason=None):
time_conversion = {"s": 1, "m": 60, "h": 3600, "d": 86400}
mute_time = int(time[0]) * time_conversion[time[-1]]
guild = ctx.guild
mutedRole = discord.utils.get(guild.roles, name="Muted by ez")
await member.add_roles(mutedRole, reason=reason)
mute = discord.Embed(
description=f"<a:mutediscord:888827254853996564> {member.mention} was muted.\n**Reason:** {reason}\n**Duration** {time}",
color=ctx.author.color)
mute.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
muteprvt = discord.Embed(
description=f"<a:mutediscord:888827254853996564> You have muted from {ctx.guild.name}\n**Reason:** {reason}\n**Duration** {time}",
color=ctx.author.color)
muteprvt.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await ctx.channel.send(embed=mute)
await ctx.member.send(embed=muteprvt)
await asyncio_sleep(mute_time)
await member.remove_roles(mutedRole)
unmute = discord.Embed(description=f"???? {member.mention} was unmuted.", color=ctx.author.color)
unmute.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await ctx.channel.send(embed=unmute)
unmuteprvt = discord.Embed(description=f"???? You have unmuted from {ctx.guild.name}", color=ctx.author.color)
unmuteprvt.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await member.send(embed=unmuteprvt)
return
if not mutedRole:
mutedRole = await guild.create_role(name="Muted by ez")
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(mutedRole, reason=reason)
mute = discord.Embed(
description=f"<a:mutediscord:888827254853996564> {member.mention} was muted.\n**Reason:** {reason}\n**Duration** {time}",
color=ctx.author.color)
mute.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
muteprvt = discord.Embed(
description=f"<a:mutediscord:888827254853996564> You have muted from {ctx.guild.name}\n**Reason:** {reason}\n**Duration** {time}",
color=ctx.author.color)
muteprvt.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await ctx.channel.send(embed=mute)
await ctx.member.send(embed=muteprvt)
await asyncio_sleep(mute_time)
await member.remove_roles(mutedRole)
unmute = discord.Embed(description=f"???? {member.mention} was unmuted.", color=ctx.author.color)
unmute.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await ctx.channel.send(embed=unmute)
unmuteprvt = discord.Embed(description=f"???? You have unmuted from {ctx.guild.name}", color=ctx.author.color)
unmuteprvt.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)
await member.send(embed=unmuteprvt)
return
这就是我的代码问题是它没有删除角色有人可以帮助我吗? 我已经转换了时间和东西,所以它一切正常,但 idk 可能 asyncio 模块不工作 bcs 也没有审计日志中的任何内容
【问题讨论】:
-
尝试使用
print语句来查看机器人卡在哪里。这是很多代码,而且很难找出错误所在。 -
如何使用它是新的,从未使用过的打印命令
-
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。
标签: python discord discord.py