0

Few days ago I decided to move all commands in my Discord Bot into an extension/cog file. After that Discord completely ignore any command (even these declared in main file). Logs are fine, there's no error or crashes. I tried many methods, that I found here, on youtube, github etc

Here is the main code:

import discord
from discord.ext import commands
import asyncio
import random
import string
import requests
import json
import os


bot = commands.Bot(command_prefix = '?')
extensions = ['cogs.com']

if __name__ == '__main__':
    for extension in extensions:
        try:
            bot.load_extension(extension)
        except Exception as error:
            print('{} cannot load the file. [{}]'.format(extension, error))

@bot.event
async def on_ready():
    await bot.change_presence(game=discord.Game(name="type `?help` for help"))
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')


@bot.event
async def on_message(message):

# here I've got a lot of bot events (responding, sending funny memes etc). Surprisingly this part works absolutely fine

bot.run("TOKEN", bot=True, reconnect=True)

And the cog file (com.py). Here I've got a lot of commands, but I decided to leave only the basic one:

import discord
from discord.ext import commands

class Com(): 
    def __init__(self, bot):
            self.bot = bot


    @commands.command()
    async def test(self):
        print('TEST') # Logs don't show anything after my command. It looks like bot doesn't even read it... or read it and doesn't send anything back?
        await self.bot.send('test')


def setup(bot):
    bot.add_cog(Com(bot))

(discord.py ver = 0.16.12)

If anyone could help, that would be awesome. Thanks

Jaku
  • 25
  • 5
  • Is the `com.py` in a `cogs` folder? If not name it only `com` in the list and not `cogs.com`. – Vassilios Oct 27 '19 at 01:55
  • Currently yes, te file is in a `cogs` folder. I've tried also without any additional folder. Nothing has changed – Jaku Oct 27 '19 at 12:00

1 Answers1

1

After a short break, I returned to this problem and I solved it by adding:

await bot.process_commands(message)

at the end of:

@bot.event
async def on_message(message):

I completely forgot about this line. That's why bot ignored my commands.

Thanks everybody, have a nice day

Jaku
  • 25
  • 5