1

It worked at first, but then somewhy it started to give the answers 4-5 times at once, any idea why?

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.event
async def once_ready():
    print('Bot is ready.')

@client.event
async def on_member_join(member):
    print(f'{member} has joined the server.')

@client.event
async def on_member_remove(member):
    print(f'{member} has left the server.')

@client.command()
async def ping(ctx):
    await ctx.send('Pong!')

client.run('my token here')
6
  • I also tried to reset the bot on my server but it didn't help.
    – J3htro
    Commented Mar 28, 2020 at 1:32
  • Does this answer your question? stackoverflow.com/questions/60750793/…
    – chluebi
    Commented Mar 28, 2020 at 14:45
  • Hi, thanks for the help. I indeed have the exact same problem, but I write it in Atom and I can't see anything to close already running instances
    – J3htro
    Commented Mar 28, 2020 at 17:59
  • Sadly I do not know enough about Atom to help you with this problem. Your best bet is probably asking in the "atom" tag.
    – chluebi
    Commented Mar 28, 2020 at 20:42
  • Yeah, I tried on Reddit as well, but probably I'm just gonna move to another compiler because I, along with others have no idea how to "fix" this. :C Thanks for your help tho :)
    – J3htro
    Commented Mar 28, 2020 at 22:59

1 Answer 1

1

So, the problem was that I couldn't shut down the already running bots in Atom.

  • If you add the code that I wrote down there (that only the owner can use) will shut down the already running bots (write /shutdown in discord server or whatever your prefix is).

However, you may need a PC restart after saving the bot with this code.

@client.command()
@commands.is_owner()
async def shutdown(ctx):
    await ctx.bot.logout()
  • So every time if you want to edit your command, you write /shutdown and edit it, after that, you can start it again.

I hope this works for you and that I could help if you had the same problem.

1
  • Late thought: You could use the atexit library for teardown
    – Quentin
    Commented Aug 27, 2020 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.