MrKvs business
MrKvs business

Reputation: 19

Why isnt my bot sending a message in discord py

My code basically does a conditional statement of a current time zone. if the time in that time zone condition is true then it sends a message pining a role. However, my code does not send a message when i put it in discord's py function

import os
import discord
from discord.ext import commands 
import datetime
import pytz


intents = discord.Intents.default() 
intents.members = True
client = commands.Bot(command_prefix = '?',intents=intents) #sets prefix 
client.remove_command('help')


f = 19
m = 0 
@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.do_not_disturb, activity= discord.Activity(name="Around ;)", type=discord.ActivityType.watching))
    print('ready')

@client.event
async def time_check():
    await client.wait_until_ready()
    while not client.is_closed:
        cst = datetime.datetime.now(tz=pytz.timezone('US/Central')).time()
        if cst.hour == 19 and cst.minute == 35:
            channel = client.get_channel(760182149839716423)
            await channel.send("<@&811801850771800134>")
            await channel.send("<@&811808231218610266>")
            await channel.send("<@&811802000463101963>")
        elif cst.hour == 19 and cst.minute == 40:
            channel = client.get_channel(760182149839716423)
            await channel.send("<@&811801850771800134>")
            await channel.send("<@&811808231218610266>")
            await channel.send("<@&811802000463101963>")
        elif cst.hour == 9 and cst.minute == 00:
            channel = client.get_channel(760182149839716423)
            await channel.send("<@&811801850771800134>")
            await channel.send("<@&811808231218610266>")
            await channel.send("<@&811802000463101963>")
        elif cst.hour == 13 and cst.minute == 00:
            channel = client.get_channel(760182149839716423)
            await channel.send("<@&811801850771800134>")
            await channel.send("<@&811808231218610266>")
            await channel.send("<@&811802000463101963>")
            break
        elif cst.hour == 18 and cst.minute == 00:
            channel = client.get_channel(760182149839716423)
            await channel.send("<@&811801850771800134>")
            await channel.send("<@&811808231218610266>")
            await channel.send("<@&811802000463101963>")
            break

client.loop.create_task(time_check())

          
client.run('TOKEN') 

Upvotes: 0

Views: 62

Answers (1)

ChrisDewa
ChrisDewa

Reputation: 642

Because "time_check" is not a valid event.

You probably want to run that as a loop.

Just do this.

from discord.ext import tasks
 # then on your time_check function, change @client.event for:

@tasks.loop(minutes=1)
async def time_check():
    # the rest of your function

#before client.run()
time_check.start()

Hope that works

Upvotes: 1

Related Questions