Reputation: 142
I was following a tutorial for discord.py and the person who was teaching was getting pretty complicated. He told use to create a main_cogs.py file and i did it.
This is the exact code as him:
import config
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='-')
class Test(commands.Cog):
def __init__(self,bot):
self.bot= bot
@commands.command
async def ping(self ,ctx):
await ctx.send("Pong")
bot.run(config.token)
BTW config is a file with the token and all that stuff.
When i run it and type -ping(in chat) i get this in the console and nothing in chat:
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "ping" is not found
for him it just works.
Thank You for the help!
Upvotes: 1
Views: 169
Reputation: 15
Hm, I use a different way of coding the bot, I'll show you my way of making a bot reply.
from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='-')
@bot.command()
async def ping(ctx):
await ctx.send('pong!')
bot.run('token')
and my opinion on the issue? It might be because of the indented block. Since that means that that would need to trigger for that to even exist in the first place. and the missing parentheses after the command
is also probably an issue. 100% recommend you to remove the block and add the parentheses before just trying what I made.
Upvotes: 0
Reputation: 130
change
@bot.command()
to @commands.command()
remove ctx from the def __init__(self,bot,ctx):
so its def __init__(self, bot):
Upvotes: 1