python - Discord.py int 没有属性 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
我没有收到错误,但机器人也没有做任何事情。提前致谢
解决方案
您正在尝试调用send
number 上的函数814588208091365426
,这是频道 ID,您需要将频道 ID 转换为具有以下内容的频道:
channel = client.get_channel(814588208091365426)
推荐阅读
- amazon-cognito - 每当更改用户属性时,是否会触发任何类型的 Cognito 回调?
- javascript - 无法在 foreach 循环中对集合中的值求和
- printing - 我们如何使用 nc 命令进行双面打印
- python - 如何使用 pandas 将两个 CSV 文档合并在一起并绘制条形图?
- node.js - 将 axios.get 请求分块,每个块延迟 1 秒 - 目前出现 429 错误
- mongodb - 如何使用 MongoDB 中的单个管道计算多个字段的频率?
- python - 如何将数组中的整数值分配给字符串数组
- elasticsearch - 每个系列的 Grafana 警报
- react-native - 无法解析模块 @react-native-masked-view/masked-view 2021
- openstack - Openstack Nodepool 在 Zuul CI 设置中为 VM 分配公共 IP