AmazingSupDawg
AmazingSupDawg

Reputation: 39

Not recognizing commands in discord with Python

I run this, it connects however when running it will not return anything when it comes to commands. I've tried changing this to the context return method from on every message. Previously only one message would appear, now none with this method even though both commands are the same with slight differences. What is my error on this? Sorry this is literally my first attempt at a discord bot.

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
botToken = os.getenv("DiscBotToken")

discClient = discord.Client()
bot = commands.Bot(command_prefix = "!")

@discClient.event
async def on_ready():
    print(f"{discClient.user} is now connected.")
    print('Servers connected to:')
    for guild in discClient.guilds:
        print(guild.name)

@bot.command(name = "about")
async def aboutMSG(ctx):
    aboutResp = "msg"
    await ctx.send(aboutResp)


@bot.command(name = "test")
async def testMSG(ctx):
    testResp = "msg"
    await ctx.send(testResp)
        

    

discClient.run(botToken)

Upvotes: 0

Views: 104

Answers (1)

Abdulaziz
Abdulaziz

Reputation: 3426

You heading in the right direction commands.Bot have both event and command no need to use a client just for events.

You should either use discord.Client or commands.Bot not both in your case it is commands.Bot.

Also you are running the client only

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
botToken = os.getenv("DiscBotToken")

bot = commands.Bot(command_prefix = "!")

@bot.event
async def on_ready():
    print(f"{discClient.user} is now connected.")
    print('Servers connected to:')
    for guild in discClient.guilds:
        print(guild.name)

@bot.command(name = "about")
async def aboutMSG(ctx):
    aboutResp = "msg"
    await ctx.send(aboutResp)


@bot.command(name = "test")
async def testMSG(ctx):
    testResp = "msg"
    await ctx.send(testResp)
        

    

bot.run(botToken)

Upvotes: 1

Related Questions