【问题标题】:Discord client Error: 'NoneType' object has no attribute 'send'Discord 客户端错误:“NoneType”对象没有“发送”属性
【发布时间】:2020-08-11 19:23:34
【问题描述】:

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

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

【问题讨论】:

  • 你使用的是哪个库?
  • “我有一个问题”根本没有概括问题

标签: python discord bots


【解决方案1】:

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

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

【讨论】:

  • 非常感谢我用了 2 个小时。祝你有美好的一天:)
  • 没问题,随时乐意提供帮助。将答案标记为已接受,以便其他人知道它已解决:)
猜你喜欢
  • 2019-12-12
  • 2020-10-22
  • 1970-01-01
  • 2021-11-12
  • 2019-10-15
  • 1970-01-01
  • 2020-10-25
  • 1970-01-01
  • 2021-08-11
相关资源
最近更新 更多