Help with discord custom responses

I trying to program a discord bot using nextcord and python. I don’t know python very well so its a learning curve. I am trying to add the ability to where admins can add custom commands. Those commands are saved in a json file. I am having an issue where the custom command gets added, the JSON file is updated, the command can be used in discord, but in the console i am getting

Ignoring exception in command None:
nextcord.ext.commands.errors.CommandNotFound: Command "test" is not found

Which is odd, because the command does work in discord. Here is my code for my admin page. Add ideas?

import nextcord
from nextcord.ext import commands
import json

class Admin(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.custom_responses = self.load_custom_responses()

    def load_custom_responses(self):
            with open("custom_responses.json", "r") as f:
                return json.load(f)
        except FileNotFoundError:
            return {}

    def save_custom_responses(self):
        with open("custom_responses.json", "w") as f:
            json.dump(self.custom_responses, f)

    async def on_message(self, message):
        if == self.client.user:
            return  # Don't respond to the bot's own messages
        content = message.content.lower()

        # Check if the message content is a trigger for a custom response
        if content in self.custom_responses:
            response = self.custom_responses[content]
        # Add more conditional statements for other responses as needed

    @commands.command(name="addresponse", help="Add a custom response for a trigger.")
    async def add_custom_response(self, ctx, trigger, *, response):
        # Allow only administrators to add custom responses
        self.custom_responses[trigger.lower()] = response
        await ctx.send(f"Custom response added for trigger: {trigger}")

        name="removeresponse", help="Remove a custom response for a trigger."
    async def remove_custom_response(self, ctx, trigger):
        # Allow only administrators to remove custom responses
        if trigger.lower() in self.custom_responses:
            del self.custom_responses[trigger.lower()]
            await ctx.send(f"Custom response removed for trigger: {trigger}")
            await ctx.send(f"No custom response found for trigger: {trigger}")

def setup(client):
1 Like

The command isn’t being found. I’m guessing in the custom_responses, you’re loading them as <prefix><command_name>, and the <prefix> is the same as the one you set with the bot. This means it’s going to work, but at the same time, it’s going to return an error that the command isn’t found, since it doesn’t actually exist.

yes you are correct. The json file has the command in it. If im not putting the command in the json file, it get that same error but no response. Below is what i have in my file, hello doesnt respond at all but goodbye does. Both have the show the error in the console.

Test was removed when I was doing some testing, hence why its not below :slight_smile:

{"hello": "Hi there!", "!goodbye": "Goodbye, have a great day!"}

That’s because you didn’t include the ! prefix

oh i understand that, my question is coming back to no matter how its formatted in that file, it gives me the error posted in the org message. Is there a way around that so it doesn’t error out in the console.