I have been trying to create a bot for Discord using the discord.py library however when I am running the program it is not sending the message as expected. It is a simple bot that is suppose to send a message every 10 minutes to a channel. I am not getting any error messages in the command line and can't seem to see any obvious errors? Any help would be greatly appreciated.
import asyncio
client = discord.Client()
async def my_background_task():
await client.wait_until_ready()
counter = 0
channel = discord.Object(id='my channel ID goes here')
while not client.is_closed:
counter += 1
await message.channel.send("TEST")
await asyncio.sleep(5) # task runs every 60 seconds
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.loop.create_task(my_background_task())
client.run('My token goes here')
message.channel.send
should probably bechannel.send
since you're setting the channel manually and not from a message. – duckboycoolawait message.channel.send("TEST")
? – duckboycoolclient.is_closed()
instead ofclient.is_closed
,channel = client.get_channel(12345)
instead ofchannel = discord.Object(id='12345')
andawait channel.send("TEST")
instead ofawait message.channel.send("TEST")
. – Benjin