'Closed Pycharm without disconnecting, and discord bot still running

I am a new programmer, trying to make a discord bot with python. Today I closed PyCharm, and did not close the running program first. As soon as I did that, the discord.py bot was still running in discord. All the commands were working with it, and the bot was online. When I restarted Pycharm, I ran the program again, and then it started working twice, and when I terminated the program, the bot was still running in discord. Here is my code and an image of what is happening-

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='r!', case_insensitive=True)
client.remove_command('help')


@client.event
async def on_ready():
    print(f'{client.user.name} is ready')


@client.command()
async def help(ctx):

    embed = discord.Embed(
        title='Training Bureau Bot',
        description='''These are all the commands you can use from this bot:
                    ----------------------------------------------------------''',
        color=discord.Colour.gold()
    )
    embed.set_thumbnail(url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')

    embed.add_field(
        name='r!help',
        value='`Shows all the commands.`',
        inline=True
    )

    await ctx.send(embed=embed)


@client.command()
async def discharge(ctx):

    allowed_people = discord.utils.get(ctx.guild.roles, name='Training Bureau Personnel')

    if allowed_people in ctx.author.roles:
        embed = discord.Embed(
            title='Discharge',
            description='''If you want to discharge, state your reason below.
                            ---------------------------------------------------------''',
            color=discord.Colour.gold()
        )
        embed.set_thumbnail(
            url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')
        await ctx.send(embed=embed)

        def check(msg):
            return msg.author == ctx.author and msg.channel == ctx.channel and \
                   msg.content.lower()

        msg = await client.wait_for('message', check=check, timeout=60)

        embed_2 = discord.Embed(
            title='Successful!',
            description='Your discharge has been successfully logged. Please wait for the HICOM to accept/deny it.',
            color=discord.Colour.green()
        )
        embed_2.set_thumbnail(
            url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')

        discharge_logs = client.get_channel(933708007097905183)

        embed_3 = discord.Embed(
            title='Discharge Notice',
            description=f'{msg.author.display_name} has written a discharge notice with the reason: "{msg.content}"\n' + '----------------------------------------------------------------------------',
            color=discord.Colour.gold()
        )
        embed_3.set_thumbnail(
            url='https://cdn.discordapp.com/icons/820075295947096154/ebcccb9506e73b0dec8818249e6cba0c.webp?size=128')

        await discharge_logs.send(embed=embed_3)
        await ctx.send(embed=embed_2)

    else:
        embed = discord.Embed(
            title='No permissions',
            description='You are not allowed to execute this command. (If you think this is a mistake, DM Burger1372.',
            color=discord.Colour.red()
        )
        await ctx.send(embed=embed)


client.run(TOKEN)

Image that I didn't execute the program

Image that even if I didn't execute, the bot was running

Please tell me how to fix this. If you could also tell me how I can make the code more efficient, it would be appreciated. :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source