0

I am trying to program a Discord bot in Python using the discord.py module.

When I run the code, it doesn't say anything, waits a little (probably importing/connecting stuff) and then closes - or in IDLE, >> appears.

There is no problem with the code, as it doesn't give any errors. Plus, if I run a command out of on_ready() it works as expected.

So the problem isn't because of not being able to connect to the bot or Discord, is it? Perhaps the asnyc function doesn't work, or the interpreter doesn't recognize it?

Here is the basic form of the main code:

    import discord
    
    token = 'blahblah'
    
    client = discord.Client()
    
    @client.event
    async def on_message(message):
           if message.content=="some input":
                  msg = 'some output'
                  await message.channel.send(msg)
    
    @client.event
    async def on_ready():
           print("All works fine!")
    
    client.run(token)

vvvvv
  • 25,404
  • 19
  • 49
  • 81
LercDsgn
  • 131
  • 12
  • I am not having the problem of the bot failing to start. Silly question, but is your bot actually in a server? How much RAM do you have? What versions of discord.py/python are you using? – Allister Sep 29 '20 at 17:25
  • 1- Yes, I already added it to my test server. 2- What should be the lowest RAM for it to work? 3- 3.8.5 (Python) - Guess 1.0.1 (Discord.py) – LercDsgn Sep 29 '20 at 17:32
  • I don't know if this issue is necessarily version related, but you should definitely update to the last version just in case. Lot of fixes can happen between 1.0.1 and 1.5.0. Also, I don't know but at least 2gb of RAM should be fine. My VM uses 2gb of ram and my test bot runs fine. That's probably not the issue. – Allister Sep 29 '20 at 17:39
  • @Allister That was night here and you answered right after I closed the computer :D, Then I saw your reply via phone but I wasn't logged in there, I thought of replying back morning, but I eventually forgot it.. Apologizes... And yes, I'll try uprading. Do we do it in cmd or download something? – LercDsgn Sep 30 '20 at 21:23
  • If you have Pip installed (which comes automatically with Python) you should just be able to use cmd to `pip install discord.py`, which will get the latest version. – Allister Sep 30 '20 at 21:26
  • @Allister Is it the latest version if it says "Requirement already satisfied" or is it just something going on in there? – LercDsgn Oct 02 '20 at 16:08
  • 1
    Requirement already satisfied means you have the package but not necessarily the right version as I understand it. I gave you the wrong command. Try https://stackoverflow.com/questions/47071256/how-to-update-upgrade-a-package-using-pip Do `pip show discord.py` to see if it worked. – Allister Oct 02 '20 at 16:46
  • @Allister Yes, it works. Thank you very much! Now it is 1.5.0 -as you mentioned in one of your older comments. Sometimes there are little problems where you know if you change a little thing, but you can't find that thing. Have a nice day! :) EDIT: That guy in the link you gave had th same problem but I couldn't notice it. – LercDsgn Oct 02 '20 at 17:35

1 Answers1

0

Since you mention something about it being an issue with async I shall leave an answer that I gave another user about async. https://stackoverflow.com/a/63005581/13950887

Another issue I had recently was due to discord updating their website from discordapp.com and discord.gg to discord.com, a way I found to resolve this was to edit a bunch of the files, one thing I will say is that I wouldn't recommend doing this unless you know what you are doing.

vvvvv
  • 25,404
  • 19
  • 49
  • 81