@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可能异步IO模块不工作,因为bcs在auditlog中也没有任何内容
添加了所有ur功能
把它修好了,事实上,只是它错了,哈哈。 所以无论谁想用它,你都可以拥有它 谢谢你的帮助,多米尼克
这个错误是由于这里的各种原因造成的
你没有像你在那里写的那样使用
asyncio
。请改为尝试asyncio.sleep(mute_time)
,因为asyncio_sleep
不存在另外,您应该知道
return
后面的代码无法访问,因为在我的屏幕截图中,后面的所有内容都被阻止。代码如何仍然适用于您是值得怀疑的屏幕截图:
另外,您应该更早地检查
mutedRole
是否存在,否则将出现AttributeError
错误。因此,只需将您的if not mutedRole:
语句放在您试图添加角色之前的某个位置相关问题 更多 >
编程相关推荐