DiabloStudio
DiabloStudio

Reputation: 35

Discord bot problem. discord.py AttributeError: 'Bot' object has no attribute 'channel'

I'm sorry that I post again today, but I'm just starting to create bots and there are many problems that I don't understand even though I dig the whole internet.

I have created a table in embed that is to be uploaded to the feed every hour, but there are bugs.

My problem: AttributeError: 'Bot' object has no attribute 'channel'

Here is my code:

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)

Upvotes: 0

Views: 2955

Answers (1)

Jakob F
Jakob F

Reputation: 1056

You need to call send() on channel which you have already defined earlier and not on bot.channel. Therefore you should edit you last line to be:

await channel.send(embed=embed)

Upvotes: 1

Related Questions