You need to enable JavaScript to run this app. discord.py编写自定义bot命令触发send()参数数量TypeError报错求助
优惠活动
大模型
产品
解决方案
定价
更多

discord.py编写自定义bot命令触发send()参数数量TypeError报错求助

问题原因
  • ctx.send() 是discord.py提供的异步方法,调用时必须添加await关键字才能正常执行
  • ctx.send()仅接受1个必选的位置参数作为发送的消息内容,你给了两个位置参数"your balance is:"和keys[ide],加上方法自带的self参数总共传入了3个参数,不符合方法定义,因此触发类型错误。
修正方案

将两个内容拼接为单个字符串传入,同时补上await关键字,修正后的代码如下:

import discord
from discord.ext import commands
client=commands.Bot(command_prefix='!')
keys=dict() 

@client.command()
async def deathcount(ctx):
  ide=ctx.author.id
  if ide in keys:
      # 用f-string拼接内容,同时加await
      await ctx.send(f"your balance is: {keys[ide]}")
  else:
      await ctx.send("please make a account")
补充说明

如果后续要切换到SQLite或CSV存储,建议在bot启动时先读取存量数据到内存,修改后异步写入持久化文件,避免高频读写出现IO冲突。

内容的提问来源于stack exchange,提问作者qweqwed fsdfsf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 17:00:03