本文介紹了在 Django 中運行 Discord 機器人的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想要一個訪問 Django 數據庫的不和諧機器人.一個明顯的解決方案是擁有 2 個單獨的腳本.我想知道是否有辦法將 Django 的 discord-bot 部分作為應用程序或其他東西.
I would like to have a discord bot that accesses a Django DB. An obvious solution is to have 2 separate scripts. I would like to know if there is a way to make the discord-bot part of the Django as an app or something else.
推薦答案
你可以在一個單獨的線程中運行一個不和諧的機器人,也可以給彼此設置屬性.同樣,如果您愿意,您也可以在不同的線程中運行 django.
You could run a discord bot in a separate thread, and also set attributes to each other. Similarly, you could run django in a different thread if you want, too.
import threading
django_app = DjangoApp() # However this works, I'm not familiar with Django
bot = discord.Bot() # commands.Bot() for the discontinued discord.py
bot.django = django_app
django_app.discord_bot = bot
thread = threading.Thread(target=lambda: bot.run(BOT_TOKEN))
thread.start()```
這篇關于在 Django 中運行 Discord 機器人的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!