【问题标题】:Discord Temporary mute Went WrongDiscord 临时静音出错了
【发布时间】:2019-07-31 19:17:01
【问题描述】:

我正在为我的不和谐制作一个临时静音命令,但我不知道我应该使用什么命令,没有给出错误。这是一个意想不到的结果,如果你能告诉我如何添加一个理由,那就太好了!.命令如下。

@bot.command(pass_context=True, name="tempmute")
@has_permissions(mute_members=True)
async def tempmute(ctx, *, target: Member):
    if target.server_permissions.administrator:
        await bot.say("Target is an admin")
    else:
        try:
            await bot.mute(target)
            await bot.say('{} got muted by {}'.format(target.mention, message.author))
        except Exception:
            await bot.say("Something went wrong")

@tempmute.error
async def tempmute_error(error, ctx):
    if isinstance(error, CheckFailure):
        await bot.send_message(ctx.message.channel, "You do not have permissions")
    elif isinstance(error, BadArgument):
        await bot.send_message(ctx.message.channel, "Could not identify target")
    else:
        raise error

但是该命令既不会使目标静音也不会暂时使目标静音,也不会发送任何错误,它只是说“出了点问题”。我也找不到一个命令,我可以在其中让调用该命令的成员排队等待 bot.say('{} 被 {}'.format(target.mention, message.author)) 静音message.author 我应该写什么来让调用命令的成员静音目标

【问题讨论】:

    标签: python bots discord.py


    【解决方案1】:

    据我所知,您不能仅通过键入 bot.mute(user) 将用户静音,您必须为他添加静音角色,然后在您的服务器中配置该角色以使其无法在任何频道中交谈。此外,我不会再像在kick 命令中那样添加*,如果您希望命令中有更多参数,而在这种情况下您不希望添加更多参数,则使用此命令。解决此问题的一种方法是:

    @bot.command(pass_context=True, name="tempmute")
    @has_permissions(mute_members=True)
    async def tempmute(ctx, target: Member):
        if target.server_permissions.administrator:
            await bot.say("Target is an admin")
        else:
            role = discord.utils.get(target.server.roles, name='Muted')#this line searched in the server if the role "Muted" exists
            await bot.add_roles(target, role) # this line adds to the user the muted role
            await bot.say("User {}, has been muted by moderator {}.".format(target.mention, ctx.message.auhtor.mention)) # this line sends an messsage
    
    @tempmute.error
    async def tempmute_error(error, ctx):
        if isinstance(error, CheckFailure):
             await bot.send_message(ctx.message.channel, "You do not have permissions")
        elif isinstance(error, BadArgument):
            await bot.send_message(ctx.message.channel, "Could not identify target")
        else:
            raise error
    

    【讨论】:

    • 谢谢您,先生,但您能告诉我如何仅出于一定的时间和原因将成员静音
    猜你喜欢
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2019-09-17
    • 2023-01-19
    • 2020-12-28
    • 2019-07-28
    • 2021-10-31
    • 2021-05-09
    相关资源
    最近更新 更多