Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

bot = commands.Bot(commandprefix="!", intents=discord.Intents.all()) def showmessage():…

  1. User

    bot = commands.Bot(command_prefix="!", intents=discord.Intents.all()) def show_message(): label["text"] = entry.get() # получаем введенный текст

    root = Tk() root.title("METANIT.COM") root.geometry("250x200")

    entry = ttk.Entry() entry.pack(anchor=NW, padx=6, pady=6)

    btn = ttk.Button(text="Click", command=show_message) btn.pack(anchor=NW, padx=6, pady=6)

    label = ttk.Label() label.pack(anchor=NW, padx=6, pady=6) def start(): bot.run('MTE0NDczOTg5MTU5MTI2NjM1NQ.GQ3wgV.Yn-pyapJysUq6ttS2d_Jt4-8ApTe71wAJPfGN8') asyncio.run(start()) root.mainloop()

    сделай чтоб работало асинхронно друг другу

  2. Assistant

    To make the code work asynchronously, you need to use the asyncio library and modify the show_message function to be an async function. Here's an updated version of the code:

    import asyncio
    from tkinter import Tk, ttk
    from discord.ext import commands
    import discord
    
    bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
    
    def show_message():
        label["text"] = entry.get()
    
    async def start():
        await bot.start('MTE0NDczOTg5MTU5MTI2NjM1NQ.GQ3wgV.Yn-pyapJysUq6ttS2d_Jt4-8ApTe71wAJPfGN8')
    
    async def stop():
        await bot.logout()
    
    asyncio.create_task(start())  # Run bot asynchronously
    
    root = Tk()
    root.title("METANIT.COM")
    root.geometry("250x200")
    
    entry = ttk.Entry()
    entry.pack(anchor=NW, padx=6, pady=6)
    
    btn = ttk.Button(text="Click", command=show_message)
    btn.pack(anchor=NW, padx=6, pady=6)
    
    label = ttk.Label()
    label.pack(anchor=NW, padx=6, pady=6)
    
    root.mainloop()
    

    In this updated code, I've added an asyncio.create_task(start()) line to start the bot asynchronously. Additionally, I've changed the bot.run() call to await bot.start() to make it asynchronous.