不和谐禁止

时间:2020-10-27 20:34:32

标签: python discord.py-rewrite

几乎,我发出了禁止命令。一切正常。但是我这样做的目的是,如果管理员设置了“审核日志”通道,则每次成员被禁止时,都会将其发送到该通道。这是设置的审核日志通道代码:

@client.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def setmodlogs(message):
    with open('modlogs.json', 'r') as f:
        modlog = json.load(f)

        modlog[str(message.guild.id)] = f'{message.channel.id}'

    with open('modlogs.json', 'w') as f:
        json.dump(modlog, f, indent=4)


    await message.channel.send(f'This channel is now set as the active moderation log channel.')

那很好,我刚刚添加了它,以使您了解如何知道频道是什么。但是这是ban命令。


@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):

    with open("modlogs.json","r") as f:
        modlog = json.load(f)

        
    if ctx.guild.id in modlog:
        lemodlog = modlog[str(ctx.guild.id)]
        moderation_log_channel = client.get_channel(lemodlog)
        embed = discord.Embed(title=f"<:banHammer:768062652563587072> You have been banned from {ctx.guild.name} ", color=member.color, timestamp=ctx.message.created_at)
        embed.add_field(name="Reason:", value=f"{reason}", inline=False)
        try:
            await member.send(embed=embed)
            await member.ban(reason=f"{reason}---Action done by {ctx.message.author.name}.",delete_message_days = 0)
            embed.add_field(name="Member Banned:", value=f"<@{member.id}>({member.id})", inline=False)
            embed.add_field(name="By Staff Member:", value=f"<@{ctx.message.author.id}>({ctx.message.author.id})", inline=False)
            await ctx.send(embed=embed)
        except:
            await ctx.send("Member's DM's are closed. They were still banned but they weren't dmed about it.")
            await member.ban(reason=f"{reason}---Action done by {ctx.message.author.name}.",delete_message_days = 0)
            embed.add_field(name="Member Banned:", value=f"<@{member.id}>({member.id})", inline=False)
            embed.add_field(name="By Staff Member:", value=f"<@{ctx.message.author.id}>({ctx.message.author.id})", inline=False)
            await moderation_log_channel.send(embed=embed)
            await ctx.send(embed=embed)
            
    if not ctx.guild.id in modlog:
        embed = discord.Embed(title=f"<:banHammer:768062652563587072> You have been banned from {ctx.guild.name} ", color=member.color, timestamp=ctx.message.created_at)
        embed.add_field(name="Reason:", value=f"{reason}", inline=False)
        try:
            await member.send(embed=embed)
            await member.ban(reason=f"{reason}---Action done by {ctx.message.author.name}.",delete_message_days = 0)
            embed.add_field(name="Member Banned:", value=f"<@{member.id}>({member.id})", inline=False)
            embed.add_field(name="By Staff Member:", value=f"<@{ctx.message.author.id}>({ctx.message.author.id})", inline=False)
            await ctx.send(embed=embed)
        except:
            await ctx.send("Member's DM's are closed. They were still banned but they weren't dmed about it.")
            await member.ban(reason=f"{reason}---Action done by {ctx.message.author.name}.",delete_message_days = 0)
            embed.add_field(name="Member Banned:", value=f"<@{member.id}>({member.id})", inline=False)
            embed.add_field(name="By Staff Member:", value=f"<@{ctx.message.author.id}>({ctx.message.author.id})", inline=False)
            await ctx.send(embed=embed)

我没有收到任何错误,所以我不太了解为什么此代码无法正常工作。任何帮助将不胜感激。

0 个答案:

没有答案