Discord bot doesn't check the messages. What's wrong?



  • import os
    import discord
    my_secret = os.environ['TOKEN']
    client = discord.Client()
    
    @client.event
    
    async def on_ready():
      print('logged in as {0.user}'.format(client))
    
    async def on_message(message):
      
      if message.author == client.user:
        print('message checked, denied')
        return
      
      if message.content.startswith(';hello'):
        print('message checked')
        await message.channel.send('hello!')
    
    client.run(os.getenv('TOKEN'))
    


  • We need to remove an empty line between the function and the decorator (this is better read) and add to the second function of the decorator (and this is already mandatory).

    @client.event
    async def on_ready():
        # ...
    

    @client.event
    async def on_message(message):
    # ...

    Is that all? I believe https://discordpy.readthedocs.io/en/latest/quickstart.html which is like yours, yes, everything.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2