Discord.py Modmail黑名单

时间:2020-11-02 23:05:42

标签: python json discord.py-rewrite

我不需要modmail本身的任何帮助。感谢帮助我并说明如何做的人,它的工作非常正常。但是我确实需要帮助来制作黑名单命令,该命令将允许某人的id存储在json文件中,并且直到他们从黑名单中删除后才允许他们使用modmail。他是我当前的黑名单代码。

@client.command()
async def blacklist(ctx, member : discord.Member=None):
    with open('blacklist.json', 'r') as f:
        users = json.load(f)
    if member==None:
        await ctx.send("Please add a member to blacklist")
    else:
        if not f'{member.id}' in users:
            users[f'{member.id}'] = 0
            f.seek(0)
            json.dump(users, f)
            await ctx.send(f"{member.name} has been blacklisted.")
        if f'{member.id}' in users:
            users.pop(str(member.id))
        with open('blacklist.json', 'w') as f:
            json.dump(users, f, indent=4)
        await ctx.send(f"{member.name} has been removed from the blacklist.")
        ```
I do not think its the problem with the blacklist command its self, but instead the modmail code. Since someone has to dm the modmail, it was suggested I use:
if message.guild:
    return

因此,该漫游器只会响应dms中的内容。不幸的是,我需要机器人响应行会中调用的命令。任何帮助,将不胜感激。 完整代码:

import discord
import asyncio
import json
from discord.ext import commands




client = commands.Bot(command_prefix='o!')






@client.event
async def on_ready():
    print("Logged in as: " + client.user.name + "\n")


cooldown_members = []

sent_users = []


@client.event
async def on_message(message):

    with open('blacklist.json', 'r') as f:
        users = json.load(f)

    if message.guild:
        return

    if message.author == client.user:
        return
    
    if message.author in users:
        await message.author.send("You are currently blacklist from using modmail.")

    if message.author.id in sent_users: 
        return

    if message.author.id in cooldown_members:
        await message.author.send("You can only send a modmail submission every 5 minutes.") 
        return
    
    sent_users.append(message.author.id) 



    modmail_channel = client.get_channel(750485129436201023)
    suggestion_channel = client.get_channel(754586926492942437)
    bot_dev_chat = client.get_channel(758426717244096526)
    event_suggestion_channel = client.get_channel(755149571604217989)

    embed = discord.Embed(color=0x00FFFF)
    embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024")
    embed.add_field(name='``Report a member``:', value=f"React with 1️⃣ if you want to report a member.", inline=False)
    embed.add_field(name='``Report a Staff Member``:', value=f"React with 2️⃣ if you want to report a Staff Member.", inline=False)
    embed.add_field(name='``Warn Appeal``:', value=f"React with 3️⃣ if you would like to appeal a warning.", inline=False)
    embed.add_field(name='``Server Suggestion``:', value=f"React with 4️⃣ if you would like to give a server suggestion.", inline=False)
    embed.add_field(name='``Event Suggestion``:', value=f"React with 5️⃣ if you would like to give a event suggestion.", inline=False)
    embed.add_field(name='``Bot Suggestions``:', value=f"React with 6️⃣ if you would like to give a bot suggestion.", inline=False)
    embed.set_footer(text="Olympia Gaming | Modmail | If you accidentally DMed modmail, just ignore this message.")
    msg = await message.author.send(embed=embed)
    await msg.add_reaction("1️⃣")
    await msg.add_reaction("2️⃣") 
    await msg.add_reaction("3️⃣")
    await msg.add_reaction("4️⃣")
    await msg.add_reaction("5️⃣")
    await msg.add_reaction("6️⃣")
    

    try:
        def check(reaction, user):
            return user == message.author and str(reaction.emoji) in ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣"]



        reaction, user = await client.wait_for("reaction_add", timeout=60, check=check)

        if str(reaction.emoji) == "1️⃣":
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024")
            embed.add_field(name='How to Report:', value="Send the ID of the person you are reporting and attach add a screen shot of them breaking a rule (can be ToS or a server rule).")
            embed.set_footer(text="Olympia Gaming | Report a member ")
            await message.author.send(embed=embed)

            message = await client.wait_for("message", timeout=60, check=lambda m: m.channel == message.channel and m.author == message.author)
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"{message.author}({message.author.id})", icon_url= message.author.avatar_url)
            embed.add_field(name='Report:', value=f"{message.content}")
            embed.set_footer(text="Olympia Gaming | Modmail")
            msg = await modmail_channel.send(embed=embed)
            msg2 = await message.author.send("You report has been sent to the staff team!")
            #await msg.add_reaction("<:like:720523703582195712>")
            await msg2.add_reaction("?")
            sent_users.remove(message.author.id)
            cooldown_members.append(message.author.id) 
            #await asyncio.sleep(5 * 60)
            await asyncio.sleep(5)
            cooldown_members.remove(message.author.id)

        if str(reaction.emoji) == "2️⃣":
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024")
            embed.add_field(name='How to Report a Staff Member:', value="Send the ID of the staff member you are reporting and attach add a screen shot of them breaking a rule, power abusing, or being unprofessional.")
            embed.set_footer(text="Olympia Gaming | Report a Staff member ")
            await message.author.send(embed=embed)

            message = await client.wait_for("message", timeout=60, check=lambda m: m.channel == message.channel and m.author == message.author)
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"{message.author}({message.author.id})", icon_url= message.author.avatar_url)
            embed.add_field(name='Staff Report:', value=f"{message.content}")
            embed.set_footer(text="Olympia Gaming | Modmail .")
            massg = await modmail_channel.send(embed=embed)
            msg2 = await message.author.send("You report has been sent to the consultants!")
            await massg.add_reaction("<:like:720523703582195712>")
            await msg2.add_reaction("?")
            sent_users.remove(message.author.id)
            cooldown_members.append(message.author.id) 
            await asyncio.sleep(5 * 60)
            cooldown_members.remove(message.author.id)            

        if str(reaction.emoji) == "3️⃣":
            embed = discord.Embed(color=0x00FFFF, inline=False)
            embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024",)
            embed.add_field(name='How to appeal a warning:', value="Send your warn ID and give a reason on why your warning should be removed.")
            embed.set_footer(text="Olympia Gaming | Warn Appeal ")
            await message.author.send(embed=embed)

            message = await client.wait_for("message", timeout=60, check=lambda m: m.channel == message.channel and m.author == message.author)
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"{message.author}({message.author.id})", icon_url= message.author.avatar_url)
            embed.add_field(name='Warn Appeal:', value=f"{message.content}")
            embed.set_footer(text="Olympia Gaming | Modmail ")
            mssg = await modmail_channel.send(embed=embed)
            msg2 = await message.author.send("Your appeal has been sent to the staff team!")
            await mssg.add_reaction("<:like:720523703582195712>")
            await msg2.add_reaction("?")
            sent_users.remove(message.author.id)
            cooldown_members.append(message.author.id) 
            await asyncio.sleep(5 * 60)
            cooldown_members.remove(message.author.id)

        if str(reaction.emoji) == "4️⃣":
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024")
            embed.add_field(name='How to give a server suggestion:', value="Send what you would like to suggest, and how it would benifit the server. **NOTE:** Any joke suggestions will result in a warn and a possible blacklist.")
            embed.set_footer(text="Olympia Gaming | Suggestions ")
            await message.author.send(embed=embed)

            message = await client.wait_for("message", timeout=60, check=lambda m: m.channel == message.channel and m.author == message.author)
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"{message.author}({message.author.id})", icon_url= message.author.avatar_url)
            embed.add_field(name='Suggestion:', value=f"{message.content}")
            embed.set_footer(text="Olympia Gaming | Suggestions | DM Modmail to give suggestions.")
            fart = await suggestion_channel.send(embed=embed)
            msg2 = await message.author.send("You suggestion has been sent to <#754586926492942437>!")
            await msg2.add_reaction("?")
            await fart.add_reaction("<:like:720523703582195712>")
            await fart.add_reaction("<:dislike:720523749249646643>")
            await suggestion_channel.send("If you like a suggestion, react with: <:like:720523703582195712>.    ") 
            await suggestion_channel.send("If you don't like a suggestion, react with: <:dislike:720523749249646643>.")
            await suggestion_channel.send("If a suggestion has <:pending:720524379393490944>, it means the suggestion is being discussed.")
            await suggestion_channel.send("If a suggestion has <:no:718177824229556346>, it means the suggestion was rejected.")
            await suggestion_channel.send("If a suggestion has <a:spinstar:710216161152729320>, it means the suggestion was accepted.")
            sent_users.remove(message.author.id)
            cooldown_members.append(message.author.id) 
            await asyncio.sleep(5 * 60)
            cooldown_members.remove(message.author.id)

        if str(reaction.emoji) == "5️⃣":
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024")
            embed.add_field(name='How to give a server suggestion:', value="Send what you would like to suggest, and how it would benifit the server. **NOTE:** Any joke suggestions will result in a warn and a possible blacklist.")
            embed.set_footer(text="Olympia Gaming | Suggestions ")
            await message.author.send(embed=embed)

            message = await client.wait_for("message", timeout=60, check=lambda m: m.channel == message.channel and m.author == message.author)
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"{message.author}({message.author.id})", icon_url= message.author.avatar_url)
            embed.add_field(name='Event Suggestion:', value=f"{message.content}")
            embed.set_footer(text="Olympia Gaming | Suggestions | DM Modmail to give event suggestions.")
            fart = await event_suggestion_channel.send(embed=embed)
            msg2 = await message.author.send("You suggestion has been sent to <#755149571604217989>!")
            await msg2.add_reaction("?")
            await fart.add_reaction("<:like:720523703582195712>")
            await fart.add_reaction("<:dislike:720523749249646643>")
            await event_suggestion_channel.send("If you like a suggestion, react with: <:like:720523703582195712>.    ") 
            await event_suggestion_channel.send("If you don't like a suggestion, react with: <:dislike:720523749249646643>.")
            sent_users.remove(message.author.id)
            cooldown_members.append(message.author.id) 
            await asyncio.sleep(5 * 60)
            cooldown_members.remove(message.author.id)

        if str(reaction.emoji) == "6️⃣":
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"Olympia Gaming Modmail System", icon_url="https://cdn.discordapp.com/icons/690937143522099220/34fbd058360c3d4696848592ff1c5191.webp?size=1024")
            embed.add_field(name='How to give a suggestion:', value="Send what you would like to suggest, and how it would benifit the bot.")
            embed.set_footer(text="Olympia Gaming | Suggestions ")
            await message.author.send(embed=embed)

            message = await client.wait_for("message", timeout=60, check=lambda m: m.channel == message.channel and m.author == message.author)
            embed = discord.Embed(color=0x00FFFF)
            embed.set_author(name=f"{message.author}({message.author.id})", icon_url= message.author.avatar_url)
            embed.add_field(name='Suggestion:', value=f"{message.content}")
            embed.set_footer(text="Olympia Gaming | Bot Suggestions")
            fart = await bot_dev_chat.send(embed=embed)
            msg2 = await message.author.send("You suggestion has been sent to the Olympia Bot Devs!")
            await msg2.add_reaction("?")
            sent_users.remove(message.author.id)
            cooldown_members.append(message.author.id) 
            await asyncio.sleep(5 * 60)
            cooldown_members.remove(message.author.id)


    except asyncio.TimeoutError:
        sent_users.remove(message.author.id)
        
    
    await client.process_commands(message)

@client.command()
async def blacklist(ctx, member : discord.Member=None):
    with open('blacklist.json', 'r') as f:
        users = json.load(f)
    if member==None:
        await ctx.send("Please add a member to blacklist")
    else:
        if not f'{member.id}' in users:
            users[f'{member.id}'] = 0
            f.seek(0)
            json.dump(users, f)
            await ctx.send(f"{member.name} has been blacklisted.")
        if f'{member.id}' in users:
            users.pop(str(member.id))
        with open('blacklist.json', 'w') as f:
            json.dump(users, f, indent=4)
        await ctx.send(f"{member.name} has been removed from the blacklist.")
        

0 个答案:

没有答案