0TheGreyPilgrim0
0TheGreyPilgrim0

Reputation: 23

Discord.py - When a command is used in Discord nothing happens

I have tried various methods that various articles and people have suggested, yet none of them seem to work. Could someone please tell me what I am doing wrong?

from discord.ext.commands import Bot
from discord.ext import commands


@bot.event
async def on_message (message):
    if message.author == client.user:
      return

    if message.content.startswith('pog'):
      await message.channel.send("We're no strangers to love You know the rules and so do I A full commitment's what I'm thinking of  You wouldn't get this from any other guy I just wanna tell you how I'm feeling Gotta make you understand Never gonna give you up, never gonna let you down Never gonna run around and desert you Never gonna make you cry, never gonna say goodbye Never gonna tell a lie and hurt you")
    
    await bot.process_commands(message)

bot = Bot(command_prefix='!')

@bot.command(name='test')
async def test(ctx):
  await ctx.send("It worked")

Please note there is more to this code, this is the only bit relating to commands.

Upvotes: 1

Views: 186

Answers (1)

IPSDSILVA
IPSDSILVA

Reputation: 1829

Well, I do see that you did leave off some parts of the code, but there are a few things, from my perspective, that I'm seeing incorrectly in your code.

First, you haven't created the bot instance that is referred to throughout the course of the code. To do that, add this right below the import statements:

bot = commands.Bot(command_prefix='YOUR_PREFIX_HERE')  # Make sure you put your prefix there and make sure to import commands from discord.ext

In addition, I know that this might not be the problem, but I am not seeing a place where you are actually "running" the bot. To do that, add this as the last line to your code:

bot.run('TOKEN HERE')

Upvotes: 1

Related Questions