不和内容

2024-09-30 16:32:26 发布

您现在位置:Python中文网/ 问答频道 /正文

import discord
import asyncio 
import asyncpg
from discord.ext import commands

async def on_message(message):
    channel = client.get_channel('654057661142269964')
    await channel.send('verify')
    await client.send_message(message.channel, "Test")
    return

 client.run(Token)

这就是我在Python3.7中使用的代码,但问题是我在Discord上没有得到响应,尽管我得到了错误:

line 13, in on_message
    await channel.send('verify')
AttributeError: 'NoneType' object has no attribute 'send'

Tags: fromimportclientsendasynciomessageasyncon
1条回答
网友
1楼 · 发布于 2024-09-30 16:32:26

首先,您混合了不同版本的不和谐.py. Client.send_message来自不和谐.pyv0.16,一个过时的版本,不再受支持。你应该调查一下migrating to v1。 注意,id实际上是该版本中的字符串。在v1更新后的最新版本中,它们只是整数。你知道吗

不管怎样,正如the documentation for^{}所说,如果找不到通道,它将返回None。您需要在使用之前添加一个检查,以查看是否找到了该频道。你知道吗

相关问题 更多 >