首页 > 解决方案 > Discord 客户端错误:“NoneType”对象没有“发送”属性

问题描述

启动时,它应该在其中一个文本通道中写入一条消息。

错误:“NoneType”对象没有“发送”属性

channel = client.get_channel(111111111)   #I have the real id
message = ("Wow")
@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
    await client.change_presence(status=discord.Status.online, activity=game)
    await channel.send(message)

标签: pythondiscordbots

解决方案


Bot一旦准备好就可以获取频道,这意味着在机器人未准备好之前您无法获取频道。正如您所看到的,您在事件之前正在做get_channel()on_ready()即在机器人准备好之前。

让频道参加on_ready活动,这应该很好。

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
    await client.change_presence(status=discord.Status.online, activity=game) #game is not defined make sure to define it
    channel = client.get_channel(channel_id)
    await channel.send("Wow")

推荐阅读