discord.py - 为什么要删除这个错误?类型错误:on_message() 缺少 1 个必需的位置参数:“消息”
问题描述
我正在尝试创建一个带有用户 id 的代码,然后检查它是否与一个匹配,如果匹配,它会发送一条消息...我不断收到错误TypeError: on_message() missing 1 required positional argument: 'message ' ...
@client.event
async def on_message(ctx,message):
member = message.author.id
if member == <userid>:
await ctx.send("yo whats up")
else:
return
await client.process_commands(message)
解决方案
您没有按照应有的方式定义您的功能。on_message
event 只接受一个参数:message
. 您将不得不在没有事件中的ctx
参数的情况下工作on_message
。考虑到这一点,您可以从以下位置重新格式化当前功能代码:
@client.event
async def on_message(ctx,message):
member = message.author.id
if member == <userid>:
await ctx.send("yo whats up")
else:
return
await client.process_commands(message)
至:
@client.event
# Only pass in "message" argument
async def on_message(message):
member = message.author.id
if member == <userid>:
# Use message.channel.send() instead of ctx.send()
await message.channel.send("yo whats up")
else:
return
await client.process_commands(message)
推荐阅读
- sql-server - ODBC 查询在 MS Access 中有效,但在 SQL Server 中超时
- java - 关于类型转换对象和访问方法的问题
- ruby-on-rails-5 - 从 Rails 视图上的 2 种不同形式获取参数
- javascript - 无法在 Python Flask 服务器上播放音频,但在本地运行良好
- docker - 主持一个容器爱好项目
- node.js - 多次请求后,Axios 未从服务器获取数据
- elasticsearch - 电报输出到 Elasticsearch:“健康检查超时:没有可用的 Elasticsearch 节点”
- r - 如何查找数据框中两列的异常值
- azure - Azure - 用于 Web 应用程序的 js、css 文件的浏览器缓存设置
- mysql - 在创建 Elastic Beanstalk 环境时,有什么方法可以在创建时在 RDS MySQL 实例中创建触发器和存储过程?