繁体   English   中英

Discord.py int 没有属性 send

[英]Discord.py int has no attribute send

嘿,所以我得到了这个代码

import discord
import asyncio
import random
import os
import time
from discord.ext import tasks, commands


client = discord.Client()

@client.event
async def on_ready():
 print('we have logged in as {0.user}'.format (client))

async def background_loop():
  await client.wait_until_ready()
  while not client.is_closed():
    channel =(814588208091365426)
    messages = ["Test1", "Test2", "Test3"]
    await channel.send(random.choice(messages))
    await asyncio.sleep(60)
    

client.loop.create_task(background_loop())
client.run(os.getenv('token'))

我收到了这个错误:

future: <Task finished name='Task-1' coro=<background_loop() done, defined at main.py:15> exception=AttributeError("'int' object has no attribute 'send'")>
Traceback (most recent call last):
  File "main.py", line 20, in background_loop
    await channel.send(random.choice(messages))
AttributeError: 'int' object has no attribute 'send'

我也尝试添加

return messages

我没有收到错误,但机器人也没有做任何事情。 提前致谢

您正在尝试调用 function send号码814588208091365426 ,这是频道 ID,您需要将频道 ID 转换为具有以下内容的频道:

channel = client.get_channel(814588208091365426)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM