【问题标题】:TypeError: event() missing 1 required positional argument: 'coro'类型错误:事件()缺少 1 个必需的位置参数:'coro'
【发布时间】:2021-12-01 14:33:12
【问题描述】:

我正在制作一个不和谐的机器人,但遇到了机器人无法启动的问题,如果你能帮助我,我将不胜感激)。该机器人是在 python 中创建的

# -*- coding: utf-8 -*-

import discord
from discord.ext import commands
from config import  token

import  youtube_dl
import os

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_ready():
    print('bot online!')

@bot.event()
async def on_message():
    print('New Message!')

bot.run(token)

【问题讨论】:

  • 您将@bot.event() 用于一个装饰器,将@bot.event 用于另一个。这是故意的吗?

标签: python python-3.x discord.py


【解决方案1】:

您应该使用 @bot.event 装饰器来处理事件。不是@bot.event()
on_message 函数也应该有 1 个参数。所以,你需要写`

@bot.event
async def on_message(message):
    pass  # whatever here

【讨论】:

  • 感谢您的帮助!
  • 那么,你能接受我的回答吗? (在它附近使用绿色勾号)
  • 好的,再次感谢!
猜你喜欢
  • 1970-01-01
  • 2022-01-19
  • 2022-01-11
  • 1970-01-01
  • 2018-09-12
  • 2021-08-05
  • 2021-07-06
  • 2021-08-05
相关资源
最近更新 更多