async def not registering the function as a coroutine
mikael last edited by
ccc last edited by
Are you sure you are running on Python 3?
JonB last edited by
Have you gotten things running before?
Try doing a force quit on pythonista, that sometimes solves wierd issues.
When you get this error, do the following:
- print the full traceback -- make sure it is barfing on the command you think it is, and not some other where you forgot the async def. also, make sure the code is checking asyncio.iscoroutinefunction, not asyncio.iscoroutine (sunce async def passes the former, but fails the latter)
pdb.pm()and explore to make sure the func is the one you think, and you can explore to make sure things are being called correctly..
@ccc I am currently running on Python 3.6
@mikael It is actually a TypeError and I am using the regular version (0.16.12).
@JonB I have gotten things running before and force quitting didn’t help, but I’ve tried it multiple times. Printing the full traceback shows that the error is being raised in core.py of the discord module, making me think that is the screwed up one, not asyncio! Even so, I tried completely reinstalling discord.py, but that didn’t work so I’m confused about that. I checked and the function running is in fact asyncio.iscoroutinefunction so that’s not what is causing the error. I don’t know how to use pdb, but when I used the command you gave me the same thing popped up as in the Traceback, just not as an error message.
JonB last edited by JonB
what might help is for you to print a complete traceback, and post. also, if you have a stripped down version of your code that displays this problem, others can help debug.
my bet is that the function it is getting hung up on maybe forgot the async. or, you have a whitespace problem, and the decorator is not being applied where you think. a full tracebCk, along with source should reveAl the issue
@JonB Full Traceback:
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/9378EF36-EE10-41EA-8875-F8ADFD217EE5/Pythonista3/Documents/CapnBot/CapnBot/CapnBot/CapnBotV1.2.8.py", line 71, in <module>
@bot.command(pass_context = True)
File "/private/var/mobile/Containers/Shared/AppGroup/9378EF36-EE10-41EA-8875-F8ADFD217EE5/Pythonista3/Documents/site-packages-3/discord/ext/commands/core.py", line 573, in decorator
result = command(*args, **kwargs)(func)
File "/private/var/mobile/Containers/Shared/AppGroup/9378EF36-EE10-41EA-8875-F8ADFD217EE5/Pythonista3/Documents/site-packages-3/discord/ext/commands/core.py", line 680, in decorator
raise TypeError('Callback must be a coroutine.')
TypeError: Callback must be a coroutine.
@JonB And here is a stripped down version of my code with just one function. All it does now is if a user sends “!hello” the bot will respond with “Hello There”. It still doesn’t work and has the same error, maybe you can try and fix it? You will have to use your own token because I’m not comfortable giving that away as it would give complete and total access over my bot and servers.
import discord from discord.ext import commands import asyncio import tokens TOKEN = tokens.my_token bot = commands.Bot(command_prefix = "!") @bot.command(pass_context = True) async def hello(ctx): await bot.say("Hello There!") bot.run(TOKEN)
Well for some weird reason, it just started working again. I did absolutely nothing to change it and yet when I tried it again for the hundredth time, it worked. Problem Solved?
JonB last edited by
Make sure asyncio does not exist in site-packages-3 or site-packages