Async code that works locally in VSC doesn't in Replit environment?

Question:
async def function calls work perfectly fine locally and I have a few async calls in my Replit, but as soon as I updated the cogs to reflect the change in the Discord API requiring cogs be run using async def instead of def and await bot.add_cog instead of bot.add_cog it won’t work in Replit.
Repl link:
https://replit.com/@LyndenSylver/DiscordBot
Here’s a very simple example:

Locally this works:

import discord
from discord.ext import commands


class Test(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def test(self, ctx):
        await ctx.send("test passed!")
        print("Test passed!")

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

This is the console log I get:

Failed to load cog cogs.currency: object NoneType can't be used in 'await' expression
Failed to load cog cogs.customhelp: object NoneType can't be used in 'await' expression
Failed to load cog cogs.dev: object NoneType can't be used in 'await' expression
Failed to load cog cogs.devtools: object NoneType can't be used in 'await' expression
Failed to load cog cogs.economy: object NoneType can't be used in 'await' expression
Failed to load cog cogs.games: object NoneType can't be used in 'await' expression
Failed to load cog cogs.login: object NoneType can't be used in 'await' expression
Failed to load cog cogs.media: object NoneType can't be used in 'await' expression
Failed to load cog cogs.settings: object NoneType can't be used in 'await' expression
Failed to load cog cogs.shops: object NoneType can't be used in 'await' expression
Failed to load cog cogs.support: object NoneType can't be used in 'await' expression
Failed to load cog cogs.time: object NoneType can't be used in 'await' expression
Failed to load cog cogs.user: object NoneType can't be used in 'await' expression

All the cogs seemed to work fine in Replit when it was this structure:

def setup(bot):
        bot.add_cog(Cogname(bot))

Not sure why async doesn’t work

It sounds like a broken Discord.py / Py-Cord (or any other fork) installation, try to reinstall your library via the Package Manager by deleting it and installing it again. If it still doesn’t work, disable guessImports in the .replit file (show it by clicking Show Hidden Files after clicking the three dots in the file list) and try reinstalling again.

uuuh… removing the library doesn’t work either…

--> poetry remove discord-py
Traceback (most recent call last):
  File "/home/runner/DiscordBot/venv/bin/poetry", line 5, in <module>
    from poetry.console import main
ModuleNotFoundError: No module named 'poetry'
exit status 1
1 Like

That seems like a very broken Repl, could you try again in a fresh one?

Perhaps even a corrupted one, happens on Replit occasionally.

Not much anymore, only really old Repls ever seem to have issues.

That worked. (meant to send this message a few days ago, but got busy)

1 Like