discord.py - 命令引发异常:AttributeError:“NoneType”对象没有属性“发送”
问题描述
我试图制作一个将消息发送到指定频道并得到以下错误的命令
Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'
@client.command(name="chmsg")
async def _chmsg(ctx):
def check(msg):
return msg.author == ctx.author and \
msg.channel == ctx.channel
await ctx.send("Message")
mestoc = await client.wait_for("message", check=check)
await ctx.send("Channel id")
chasend = await client.wait_for("message", check=check)
mestoch = str(mestoc.content)
cha = str(chasend.content)
channel = client.get_channel(cha)
await channel.send(f"{mestoch}")
解决方案
您不必转换
mestoc.content
为字符串,因为它已经是字符串你需要
cha
一个整数,而不是一个字符串,这样你就可以得到频道
所以你修改后的代码看起来像
@client.command(name="chmsg")
async def _chmsg(ctx):
def check(msg):
return msg.author == ctx.author and \
msg.channel == ctx.channel
await ctx.send("Message")
mestoc = await client.wait_for("message", check=check)
await ctx.send("Channel ID")
chasend = await client.wait_for("message", check=check)
mestoch = mestoc.content
cha = int(chasend.content)
channel = client.get_channel(cha)
await channel.send(f"{mestoch}")
推荐阅读
- python - 使用 for 和 while 循环编写素数函数的最 Pythonic 方式是什么?
- ruby-on-rails - 在 Ruby 中的表单内调用另一个控制器
- c# - 所需功能已贬值,如何使其 appium 与 Android 驱动程序一起使用?
- angular - NgbDropdown 下拉按钮的自定义箭头
- c# - 如何在 C# 中将 char 与字符串一起使用?
- python - X-13-ARIMA 与 statsmodels.tsa.x13
- code-analysis - 如何持久化 NDepend 项目的分析结果?
- python - python包装列表并在美丽的汤中转换类型
- c++ - CeilLog2函数中变量BitMask的实际作用是什么?
- python - 为什么我的 python 脚本不能作为 Mac 应用程序运行?