Reporter

Administrator
[PyCord] Getting some issues when starting the bot

I am getting some issues when starting my discord bot.

​

My code:

import discord, sys, os, asyncio; from discord.ext import commands; from private import *; from variables import database

applicationid = bot_info.application_id
bot = commands.Bot(intents = discord.Intents.all(), command_prefix = ['.'], application_id = applicationid)
bot.remove_command('help')

print("Testing connection to the database...")
async def connect_mysql():
try:
db = database.db
exec = db.cursor(buffered=True, dictionary=True)
exec.execute("SELECT welcomemessage FROM messages;")
result = exec.fetchall()
for x in result:
working = x["welcomemessage"]
print(working)
db.close()
exec.close()
except Exception as e:print(e)


print("Obtaining discord token from private py file...")
token = token.DISCORD_TOKEN
if not token:
print('ERROR: Token variable is missing: DISCORD_TOKEN')
sys.exit(-1)

async def load_extensions():
print("Getting cog files...")
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")

async def login():
await connect_mysql()
await load_extensions()
await bot.start(f'{token}')
print("Logging in to discord bot using token...")
asyncio.run(login())

Output:

❯ python bot.py
Testing connection to the database...
Obtaining discord token from private py file...
Pulled this message from Database, connection works.
Getting cog files...
/home/<My name>/.local/lib/python3.11/site-packages/discord/cog.py:786: RuntimeWarning: coroutine 'setup' was never awaited
setup(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/home/<My name>/astro/bot.py", line 42, in <module>
asyncio.run(login())
File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/<My name>/astro/bot.py", line 39, in login
await load_extensions()
File "/home/<My name>/astro/bot.py", line 35, in load_extensions
await bot.load_extension(f"cogs.{filename[:-3]}")
TypeError: object list can't be used in 'await' expression

I don't know if it helps, but here is a screenshot of the error in my terminal:

[https://ibb.co/wswNKPV](https://ibb.co/wswNKPV)

&#x200B;

&#x200B;

&#x200B;

If I remove await from

await bot.load_extension(f"cogs.{filename[:-3]}")

&#x200B;

Then it gives the following output:

❯ python bot.py
Testing connection to the database...
Obtaining discord token from private py file...
Pulled this message from Database, connection works.
Getting cog files...
/home/<My name>/.local/lib/python3.11/site-packages/discord/cog.py:786: RuntimeWarning: coroutine 'setup' was never awaited
setup(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/home/<My name>/.local/lib/python3.11/site-packages/discord/cog.py:786: RuntimeWarning: coroutine 'setup' was never awaited
setup(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Screenshot of error without await: [https://ibb.co/dJTQfFx](https://ibb.co/dJTQfFx)

It seems to run the bot, but not load any cogs.

&#x200B;

&#x200B;

Here is an example of one of my cogs:

import requests, asyncio, discord, time; from discord.ext import tasks, commands; from datetime import date; from steam import game_servers; from variables import database

class skial(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.skialchat.start()

* A lot of code here *


async def setup(bot):
await bot.add_cog(skial(bot))

Does anyone have a solution to my issue? Thanks in advance.

Author: RealSunstep

http://www.reddit.com/r/Discord_Bot...rd_getting_some_issues_when_starting_the_bot/