2
2
20two.may2020-09-25 23:06:05
Python
20two.may, 2020-09-25 23:06:05

Why doesn't the code run? Where is the mistake?

Error:
Traceback (most recent call last):
File "bot.py", line 465, in
@client.event()
TypeError: event() missing 1 required positional argument: 'coro'

@client.event()
async def on_group_remove(ctx, channel, member):
  cursor.execute("UPDATE users SET onchannel = 0 WHERE name = {}").format(member.name)
@client.event()
async def on_group_join(ctx, channel, member):
  cursor.execute("UPDATE users SET onchannel = 1 WHERE name = {}").format(member.name)
async def vccash(ctx):
  while True:
    for x in cursor.execute("SELECT onchannel, name FROM users").fetchall():
      if x[0] == 1:
        cursor.execute("UPDATE users SET cash = cash + 1 WHERE name = {}").format(x[1])
    await asyncio.sleep(20)


ps the vccash function is written in on_ready()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-09-26
@20two_may

The decorator client.eventshould not be called: https://discordpy.readthedocs.io/en/v1.4.1/api.htm...

@client.event  # вызов функции-декоратора (скобки) отсуствует
async def on_ready(): 
    print('Ready!')

Also a little tip: Try to refrain from blocking libraries/functions, especially if there are asynchronous counterparts: https://pypi.org/project/aiomysql/
Also: "listeners" on_group_*on the bot client are absolutely useless, since discord does not provide the ability to add bots into "groups"
If you want to track user login to the server, you need "listeners" of the dischargeon_guild_*

6
69MyCoPkA69, 2020-09-26
@69MyCoPkA69

The error is likely due to a missing required "coro" argument.

spoiler
Если пишете бота с помощью стороннего модуля, то почитайте его документацию, скорее всего там написано, как правильно это использовать и что должно быть в аргументе "coro".
Либо воспользуйтесь IDE с подсказками, дополнениями и прочим функционалом.
К примеру, PyCharm или что-то похожее.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question