bot = commands.Bot(commandprefix="!", intents=discord.Intents.all()) def showmessage():…
- 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()
сделай чтоб работало асинхронно друг другу
- Assistant
To make the code work asynchronously, you need to use the
asynciolibrary and modify theshow_messagefunction 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 thebot.run()call toawait bot.start()to make it asynchronous.