I need a little help with making my python Discord bot run another python script that contains a timer in it. I am not very used to if name == "main": but I thinks that the solution. So, whenever my bot is up, and I say for example $account, it has to run another python file in the same folder and start a countdown in the chat. MAIN DISCORD BOT FILE:
import nextcord
from nextcord import Interaction
from nextcord.ext import commands
intents = nextcord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix = '!', intents=intents)
@client.event
async def on_ready():
print("The bot is now ready for use")
testingServerID = 1006122650088775731
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$account'):
#(RUN TIMER HERE)
await message.channel.send("COUNTDOWN")
else:
await message.channel.send("Please use **/account** to get a new account")
client.run('TOKEN')
AND THE timer file is here:
import time
# define the countdown func.
def countdown(t):
while t:
mins, secs = divmod(t, 60)
timer = '{:02d}:{:02d}'.format(mins, secs)
print(timer, end="\r")
time.sleep(1)
t -= 1
print('Fire in the hole!!')
# input time in seconds
t = 20
# function call
countdown(int(t))