Discord客户端错误:“ NoneType”对象没有属性“发送”

时间:2020-08-11 11:18:39

标签: python discord bots

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

错误:“ 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)

1 个答案:

答案 0 :(得分:1)

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")