当前位置: 首页 > 知识库问答 >
问题:

不和谐暂时沉默出了问题

弘康安
2023-03-14

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

@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

但该命令既不使目标静音或临时静音,也不发送任何错误,它只是说“出了问题”。我也找不到一个命令,在其中我可以得到的成员谁调用了命令行等待机器人。比如({}被{}禁用了)。格式化(target.notice,message.author))消息。作者:我应该写什么来代替它来让调用命令的成员使目标静音

共有1个答案

葛霄
2023-03-14

据我所知,你不能仅仅通过键入bot.mute(user)来静音用户,你必须给他添加一个静音角色,然后在你的服务器中配置该角色,使其不能在任何频道上说话。同样,我也不会再像在king命令中那样,为什么要添加*,如果您期望在命令中有更多的参数,则会使用此命令,而在本例中不会。一种方法是这样的:

@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
 类似资料:
  • 我目前正在编写一个discord bot反应角色命令。 一切都很顺利,但我有一个问题。 当我启动机器人并运行创建嵌入的命令时,一切都很好。问题是当我对信息做出反应时,它并没有给我这个角色。这是我的代码:

  • 几个月来,我一直在我的不和谐机器人中使用相同的反应角色代码,但是突然在过去的几天里,机器人不会给任何人任何角色。我不知道怎么了。我的机器人有权限,我不会返回任何类型的错误消息。这是我添加和删除角色的代码。 在这里定义。 这是我希望人们对这个角色做出反应的信息。

  • 我已经创建了一个bot,它现在在我的discord服务器中,使用下面的代码。 我的问题是,一旦我在与bot不和谐的聊天中,我如何调用命令让bot运行代码,为用户列表收集csv?我不确定如何调用机器人,一旦它在聊天/服务器中获得列表。

  • 有时当gdb输出信息较多时,gdb会暂停输出,并会打印“---Type <return> to continue, or q <return> to quit---”这样的提示信息,如下面所示: 81 process 2639102 0xff04af84 in __lwp_park () from /usr/lib/libc.so.1 80 process 2573566

  • 我有一些不和谐的问题。js删除函数。我使用这段代码在从频道中删除图像时从用户的余额中删除1点,这是第一次一切正常,但当我尝试删除我发送的另一个图像时,机器人将从我的余额中删除1点,而不是从我的余额中删除1点,因为从机器人启动开始,总共删除了多少图像。示例:我删除一个图像,机器人将从我的余额中删除1个点,然后如果我删除我上传的另一个图像,而不是删除1个点,它将从我的余额中删除2个点,因为它将计算删除

  • 我做了很多关于如何阻止一个频道使用命令的研究,比如Rythm的黑名单,但是我没有找到,有人能帮我吗?