【问题标题】:How can I reverse this function in discord.py?如何在 discord.py 中反转此功能?
【发布时间】:2021-09-01 00:52:48
【问题描述】:

所以,我发出了静音命令,但无法弄清楚当键入“%unmute @user”时要采取什么步骤来删除角色“静音”。这是静音命令的代码:

@commands.has_permissions(manage_messages=True)
@bot.command(name='mute', help='Use %help mute to see full description... Mutes the mentioned user by adding a role to them. If the role is absent, the bot will make one. Requires permissions: Manage Messages')
async def mute(ctx, member: discord.Member, *, 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)
    embed = discord.Embed(title="muted", description=f"{member.mention} was muted ", colour=discord.Colour.light_gray())
    embed.add_field(name="reason:", value=reason, inline=False)
    await ctx.send(embed=embed)
    await member.add_roles(mutedRole, reason=reason)
    await member.send(f" you have been muted from: {guild.name} reason: {reason}")

谢谢!

【问题讨论】:

  • 我可能已经想通了。我需要一点……
  • 如果您弄明白了,请务必将您的解决方案发布为未来读者的答案。

标签: python discord.py


【解决方案1】:

我想通了!这是生成的代码:

@bot.command(name='unmute', help='Unmutes the mentioned user. Requires permissions: Manage Messages')
async def unmute(ctx, member: discord.Member, *, reason=None):
    guild = ctx.guild
    mutedRole = discord.utils.get(guild.roles, name="Muted")

    embed = discord.Embed(title="unmuted", description=f"{member.mention} was unmuted ", colour=discord.Colour.light_gray())
    await ctx.send(embed=embed)
    await member.remove_roles(mutedRole)
    await member.send(f" you have been unmuted from: {guild.name}")

打扰各位了!

【讨论】:

    猜你喜欢
    • 2021-08-17
    • 2021-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多