Python – Sending message every minute in discord.py

botsdiscorddiscord.pydiscord.py-rewritepython

I am trying to make the bot send a message every minute in discord.py. I do acknowledge that this is a easy thing to do but I have tried multiple times but resulting with no luck. I have not gotten any error messages.

Here is my code:

import discord
from discord.ext import tasks

client = discord.Client()

@tasks.loop(minutes=1)
async def test():
    channel = client.get_channel(CHANNEL_ID)
    channel.send("test")

test.start()

client.run(TOKEN)

Best Answer

You try to get channel with get_channel(), but your bot is not ready yet. So you get NoneType object, not channel. Try to this solution:

@tasks.loop(minutes=1)
async def test():
    channel = client.get_channel(CHANNEL_ID)
    await channel.send("test")

@client.event
async def on_ready():
    test.start()
Related Topic