Reporter

Administrator
[PyCord] Getting some errors on Start up

Hi everyone,

​

I have a Discord Bot, but it is currently not working. To quickly get to the point, I will now show my code and what errors I am getting:

​

My code:

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

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"):
await 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())

This results in 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
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

Now, if I remove await from

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

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

The bot seems to start, but it is not loading any cogs.

&#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

* Some code *


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

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

Author: RealSunstep

http://www.reddit.com/r/Discord_Bots/comments/zcdh9u/pycord_getting_some_errors_on_start_up/