Skip to content
Live countdown bot for Discord
Profile icon
yyd22002

I'm trying to develope a bot that can live countdown in the channel.

If a user type '!t', then the bot will send a message with 'Timer is running - 5 seconds' and it keeps mentioning exactly the time remaining in the same message every time the time passes by 1 second such "Timer is running - 3 seconds, Timer is running - 1 seconds"....
And when it reaches 0 seconds then the message will be 'Timer ends - 0'

I just google it and found some code to apply this function, but have no idea if it's correct. Could anyone help one this?

import discord
import random
import os
import time

client = discord.Client()

@client
.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))

@client
.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('!t'): Text = "" learn = message.content.split(" ") vrsize = len(learn) vrsize = int(vrsize) for i in range(1, vrsize): Text = Text + " " + learn[i] secint = int(Text) sec = secint for i in range(sec, 0, -1): print(i) await client.send_message(message.channel, embed=discord.Embed(description='Timer is running : '+str(i)+'second')) time.sleep(1) else: print("GO") await client.send_message(message.channel, embed=discord.Embed(description='Timer ends'))

client.run(os.getenv('TOKEN'))

You are viewing a single comment. View All
Profile icon
Hyderite

If you did, type TOKEN=(your discord bot token here) into the .env file