'Pycord (Discord Bot) Inside Django View
So, I run a rather larger discord bot (couple thousand users atm, trying to grow it). On the same server, I have a Django instance that I use for model storage and web dev. I'm trying to implement an admin panel using some of the model information, but also some information from the discord API. Unfortunately, however, the way that Pycord/Discord.py bots are started, the function is continuous, so I can't just run things normally. So to get the Discord information in a view, I'm attempting this.
async def baseAdmin(request):
intents = discord.Intents.default()
intents.members = True
intents.messages = True
intents.guilds = True
intents.presences = True
bot = discord.Bot(intents=intents)
print('1')
@bot.event
async def on_ready():
print('3')
n = bot.get_guild(815846750652465202)
name = n.name
await bot.close();
print("4")
return render(request, 'website/success.html')
print("2")
bot.run("MYTOKEN");
However, nothing works. I've tried going back and forth between sync and async views, using bot.run with and without an await, and a couple more things. Alas, nothing works. With this specific set, I'm getting an asyncio.exceptions.CancelledError result, but errors have been all over the place. Any assistance is GREATLY appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
