#TypeError object dict can't be used in 'await' expression

1 messages · Page 1 of 1 (latest)

ruby vale
#

hey, im trying to use py-cord to make a custom help command, but im running into an issue. When i use discord-py everything works fine however when i uninstall it and switch to py-cord it doesnt seem to work. This is the error im getting File "C:\Users\jan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 382, in _run_event await coro(*args, **kwargs) File "C:\Users\jan\Desktop\code\botty.py", line 15, in on_ready await bot.load_extension(f"cogs.{filename[:-3]}") TypeError: object dict can't be used in 'await' expression

ruby vale
compact cedar
#

?

#

send the code

#

where you load the cogs

limber latch
pseudo wigeon
#

also add store=False to load_extension

full hatch
#

how are you doing filename part?

ruby vale
# limber latch send your new code
def load_cogs():
  for filename in os.listdir("./cogs"):
    if filename.endswith(".py"):
      bot.load_extension(f"cogs.{filename[:-3]}", store=False)

@bot.event
async def on_ready():
  await bot.change_presence(activity=discord.Activity(name="typing races", type=discord.ActivityType.competing, status=discord.Status.idle))
  print("Everything's all ready to go!")

load_cogs() ``` when i run this, i get ```
 RuntimeWarning: coroutine 'setup' 
was never awaited
  setup(self)```
#

and when i keep it in async with await in the @bot.event i get TypeError: object list can't be used in 'await' expression

compact cedar
ruby vale
# compact cedar Can you show the setup in the cog?
class help(commands.Cog, name="Help"):
    """Shows help info for commands and cogs"""

    def __init__(self, bot):
        self._original_help_command = bot.help_command
        bot.help_command = help_cmd()
        bot.help_command.cog = self
        self.bot = bot

async def setup(bot: commands.Bot):
    await bot.add_cog(help(bot))```
compact cedar
#

Remove the async and the await in the setup

ruby vale
#
  File "C:\Users\jan\Desktop\code\botty.py", line 15, in on_ready
    await bot.load_extension(f"cogs.{filename[:-3]}", store=False)
TypeError: object list can't be used in 'await' expression``` still
compact cedar
#

It should be only

def setup(bot)
bot.add_cog(name(bot))
ruby vale
#

removed commands.Bot too

ruby vale
#

i removed the original cog, to see if that was the issue but i guess not, i made a second cog thats really simple ```py
import discord
from discord.ext import commands

class Ping(discord.Cog, name="Ping"):
def init(self, bot):
self.bot = bot

COG_EMOJI = "🏓"  

@commands.slash_command(name="ping", description="Ping command", guilds_id=[guildid])
async def ping(self, ctx):
  await ctx.send("Pong!")

@commands.slash_command(name="ping2", description="Ping command", guilds_id=[guildid])
async def ping2(self, ctx):
  await ctx.send("Pong!")

def setup(bot):
bot.add_cog(Ping(bot))and it still doesnt load the cog
await bot.load_extension(f"cogs.{filename[:-3]}", store=False)
TypeError: object list can't be used in 'await' expression```

sly river
#

slash commands don't use interaction as a parameter

#

they use ApplicationContext

ruby vale
sly river
#

maybe because bot.load_extension is not async?

#

so you don't await it

pseudo wigeon
ruby vale
#

yeah, i already fixed it, just wanted to say that. thanks though

pseudo wigeon
#

ahok

sly river
#

👉 /close