Search code examples
pythonpython-3.xdiscorddiscord.py

(discord.py) Bot doesn't respond to any message sent by the member. (No errors encountered)


I am coding a bot for my server. But I can't really seem to find what the problem is. Before I had added a help command (s!help) and a ping command (s!ping) the bot was responding all fine. But after I added it, it just doesn't respond to any command. I even encountered no errors. Please help?

Also: The bot is online and it prints that it is connected to Discord and no errors.

Here's my bot's code:

from keep_alive import keep_alive
import discord
import os
import asyncio

client = discord.Client()

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='SqdNoises\' Lounge'))
    print("Connected to Discord as {0.user}".format(client))

async def on_message(message):
    msg = message.content
    sendmsg = message.channel.send
    author = message.author
    mention = message.author.mention
    reply = message.reply 
    channel = message.channel
    typing = message.channel.trigger_typing
    dm = await message.author.create_dm()
    delete = message.delete

    if author == client.user:
        return

    if msg.lower() == 'hi':
      await typing()
      await asyncio.sleep(0.5)
      await sendmsg('hello ' + mention + '!')

    if msg.lower() == 'hello':
      await typing()
      await asyncio.sleep(0.5)
      await sendmsg('hello ' + mention + '!')

    if (msg.lower()).startswith('hi i am new'):
      await typing()
      await asyncio.sleep(0.5)
      await reply('hello new!')

    if (msg.lower()).startswith('ping me'):
      await typing()
      await asyncio.sleep(1)
      await sendmsg('ok, ' + mention + ' šŸ‘')

    if (msg.lower()).startswith('hi im new'):
      await typing()
      await asyncio.sleep(0.5)
      await reply('hello new!')

    if (msg.lower()).startswith('hi i\'m new'):
      await typing()
      await asyncio.sleep(0.5)
      await reply('hello new!')

    if msg.lower() == 'dm me':
      await typing()
      await asyncio.sleep(0.5)
      await sendmsg('Check your DMs for a message from me!')
      await dm.send('I DMed you as you asked me to. šŸ˜Š')

    if msg == 's!ping':
      await typing()
      await sendmsg('**Summon\'s Latency: ' + str(client.latency) + 'ms**')

    if msg == 's!help':
      await typing()
      await asyncio.sleep(1)
      await sendmsg('Oh you need help? Check your DM\'s for a message from me!')
      await dm.send('*Somebody once told me the world is maccaroni...*\n\n**Summon -- Help (s!help)**\n*Please note: This bot is not for use in any other servers. This is just a personal bot for SqdNoises\' Lounge.*\n**Commands:**\nĀ»dm me - DM\'s a message to you.\nĀ»hi - sends you a hello\nĀ»hi i am (message) - replies with \"hello (message)!\"\nĀ»ping me - pings you\nĀ»hi/hello - says hello to you\ns!ping - sends the ping of bot\n\n*Bot made and coded by SqdNoises*')

keep_alive()

token = os.environ['TOKEN']
client.run(token)

Can you please tell me what's wrong?


Thanks in advance. -sqd


Solution

  • You didnt put @client.event on top of your async def on_message