【发布时间】:2021-02-11 05:05:28
【问题描述】:
很抱歉今天又发帖了,不过我才刚开始做机器人,有很多问题我挖了全网还是不明白。
我在 embed 中创建了一个表格,每小时上传到提要,但是有错误。
我的问题:
AttributeError: 'Bot' object has no attribute 'channel'
这是我的代码:
bot = commands.Bot(command_prefix='.')
@bot.event
async def on_ready():
crypto_hour.start()
print('Bot is active!')
@tasks.loop(hours=10)
async def crypto_hour():
channel = bot.get_channel(809155804170682408)
embed = discord.Embed(
title = ":D",
color = discord.Color.blue(),
)
url = 'http://api.coinlayer.com/live?access_key='
async with aiohttp.ClientSession() as session:
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
embed.set_author(name=':D')
embed.add_field(name='• **Bitcoin (BTC)**:', value=str(f"{response['rates']['BTC']}PLN"), inline=True)
embed.add_field(name='• **Ethereum (ETH)**:', value=str(f"{response['rates']['ETH']}PLN"), inline=True)
await bot.channel.send(embed=embed)
【问题讨论】:
标签: python-3.x discord discord.py