不和谐静音命令

时间:2020-04-01 13:14:43

标签: python python-3.x bots discord discord.py

我目前正在尝试制作一个能够使用户静音的不和谐机器人。到目前为止,我已经创建了此脚本,该脚本允许具有“ staff”角色的人员运行该命令,并为标记的用户提供“ Mute”角色。如果还不存在,它还会创建一个。问题是下面的代码不起作用。它在控制台中什么也没有说,但是如果您具有职员角色并运行命令,则不会发生任何事情。

@commands.has_role("staff")
async def mute(ctx, member: discord.Member=None):
    guild = ctx.guild
    if (not guild.has_role(name="Muted")):
        perms = discord.Permissions(send_messages=False, speak=False)
        await guild.create_role(name="Muted", permissions=perms)
    role = discord.utils.get(ctx.guild.roles, name="Muted")
    await member.add_roles(role)      
    print("? "+member+" was muted.")
    if (not member):
        await ctx.send("Please specify a member to mute")
        return
@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.CheckFailure):
        await ctx.send("You don't have the 'staff' role")  

1 个答案:

答案 0 :(得分:1)

此特定行:

print("? "+member+" was muted.")

在终端或运行命令的任何位置打印它。尝试await ctx.send另外,如果您的Python版本> 3.6,请尝试使用f字符串。另外,您的错误是错误的。

@client.command()
@commands.has_role("staff")
async def mute(ctx, member: discord.Member):
    role = discord.utils.get(ctx.guild.roles, name="Muted")
    guild = ctx.guild
    if role not in guild.roles:
        perms = discord.Permissions(send_messages=False, speak=False)
        await guild.create_role(name="Muted", permissions=perms)
        await member.add_roles(role)
        await ctx.send(f"?{member} was muted.")
    else:
        await member.add_roles(role) 
        await ctx.send(f"?{member} was muted.")     

@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.MissingRole):
        await ctx.send("You don't have the 'staff' role") 
@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        await ctx.send("That is not a valid member")