【问题标题】:Having an error on discord loop, channel send不和谐循环出错,通道发送
【发布时间】:2021-12-24 09:40:14
【问题描述】:

所以我的问题是每当我尝试使用循环时,它都会给我一个错误,称为: await channel.send('没有人在线!') AttributeError: 'NoneType' 对象没有属性 'send'

我已经尝试在 @client.command() 上使用它并且没有问题。你能帮帮我吗?

@tasks.loop(seconds = 40)
async def t():
  channel = client.get_channel(908484216084385853)
               .
               .
               .
  if len(error_list) == len(names):
    await channel.send('Nobody is online!')
  else: 
    for i in range(len(friends_list)):
       await channel.send(friends_list[i].capitalize())
  

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    这可能是由于速率限制。您可以将其分配给全局变量,而不是每次调用函数时都调用 client.get_channel

    例如:

    
    async def on_ready():
      global channel
      channel = client.get_channel(908484216084385853)
      t.start()
    
    @tasks.loop(seconds = 40)
    async def t():
      
                   .
                   .
                   .
      if len(error_list) == len(names):
        await channel.send('Nobody is online!')
    
      else: 
        for i in range(len(friends_list)):
           await channel.send(friends_list[i].capitalize())
    

    【讨论】:

      猜你喜欢
      • 2021-09-27
      • 2020-12-18
      • 2019-12-10
      • 2020-05-07
      • 2020-04-07
      • 2021-01-19
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多