Reputation: 39
I think I'm doing something wrong. If I try to use to print a message in console it does work but if I try to send a message to discord I can't get it to work.
import discord
import asyncio
from discord.ext import commands
import schedule
import time
TOKEN = 'xxx'
client = commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
print('Bot Online.')
async def job():
channel = client.get_channel('XXXX')
messages = ('test')
await client.send_message(channel, messages)
schedule.every(5).seconds.do(job)
while True:
schedule.run_pending()
time.sleep(1)
client.run(TOKEN)
I modified the code but I still get this message:
RuntimeWarning: coroutine 'job' was never awaited self._run_job(job)
Upvotes: 0
Views: 4604
Reputation: 566
You need to use async
on all functions, not just on the on ready. The function name is also called on_member_join
.
@client.event
async def on_member_join(member):
await client.send_message(member, message)
The reason you have to dm the member and not send a message to a channel, is because no channel is specified.
Lets say you wanted to send a message to a specific channel you would have to do:
@client.event
async def on_member_join(member):
await client.send_message(client.get_channel('12324234183172'), message)
Replace the random number with the channel id.
If you want to read more about discord.py, you could read the docs or view a tutorial. Discord.py Docs
Note: Make sure to include import asyncio
at the top of your page.
EDIT:
Another problem is that you did schedule.every(5).seconds.do(job)
. Change this line to: await schedule.every(5).seconds.do(job)
Upvotes: 1