0

I don't know what I have done wrong and what i have changed. All of a sudden my discord bot code doesnt work. Please help me. I have tried lots of things and have checked if my cogs are loading properly and they are. I am not getting any errors either. Sorry if it is just a stupid mistake that I dont see as this is my first question on Stack Overflow.

An example of a command that doesn't work:

@bot.command()
async def test(ctx):
    await ctx.send("help me")

A cog that doesn't work:

#Imports
import discord
from discord.ext import commands
import random
import json
from pathlib import Path

#Current Working Directory
cwd = Path(__file__).parents[1]
cwd = str(cwd)

#Secret
secret_file = json.load(open(cwd+('\secrets.json')))

#Setup
class Basic(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_ready(self):
        print("Bot basic commands are online.\n---------")

    #Greeting
    @commands.command(aliases = ["hello", "hey"], description = "Greets you.")
    async def hi(self, ctx):
        embed = discord.Embed(colour=0x1ABC9C)
        embed.title = "Hey there!"
        embed.description = f"Nice to see you **{ctx.author.mention}**"
        await ctx.send(embed = embed)

#Add Cog
def setup(bot):
   bot.add_cog(Basic(bot))

I am new here sorry if it is a stupid mistake. Thanks alot!

PS: I am happy to attach more code.

Edit: My main code (if needed)

Imports
import discord
import os
from discord.ext import commands, tasks
import random
import logging
from itertools import cycle
from discord import user
import asyncio
import time
import json
from pathlib import Path

#---------------------------------------------------------------------

#Define a few things...
choice = random.choice
randint = random.randint

#Current Working Directory
cwd = Path(__file__).parents[0]
cwd = str(cwd)

#Json
secret_file = json.load(open(cwd+('\secrets.json'))) #Secrets

#Json Variables
TOKEN = secret_file["token"]

#---------------------------------------------------------------------

#Setup
bot = commands.Bot(command_prefix = "-", case_insensitive = True, owner_id = 567327597642383420)
bot.remove_command('help')

@bot.event
async def on_ready():

    bot.loop.create_task(change_status())

    await asyncio.sleep(0.5)

    print(f'Logged in as: {bot.user.name}\n---------')
    print(f'Id: {bot.user.id}\n---------')
    print(f"Path: {cwd}\n---------")

#----------------------------------------------------------------------------

#Functions

#Change Status
async def change_status():
    await bot.wait_until_ready()

    #Local Variables
    statuses = [f"| By Kwuartz_", "| -help"]
    statusnum = 0

    #Loop
    while not bot.is_closed():

        #StatusNumChanger
        if statusnum == 0:
            statusnum = 1

        else:
            statusnum = 0



        await bot.change_presence(activity = discord.Game(name = statuses[statusnum]))
        await asyncio.sleep(5)
        print("Status Changed!\n---------")

#-------------------------------------------------------------------------

#Cog Setup
for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        filename = filename[:-3]
        bot.load_extension(f'cogs.{filename}')


print("All cogs have been succesfully loaded and will be online shortly\n---------")

@bot.command()
async def test(ctx):
    print("yes")
    await ctx.send("help me")
    print("command called")

#---------------------------------------------------------------------------

#Events
@bot.event
async def on_member_join(member):
    print(f'{member} has joined the server')

@bot.event
async def on_member_remove(member):
    print(f'{member} has left the server')

@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        embed = discord.Embed(colour=0x1ABC9C)
        embed.title = "**Command Error:**"
        embed.description = f":x: **Why this happened:**\nThe command you specified does not exist."
        await ctx.send(embed = embed)

    else:
        raise error

@bot.event
async def on_message(message):
    if bot.user.mentioned_in(message):
        await message.channel.send("You can type `-help` for more info")

#Token
bot.run(TOKEN)
Kwuartz_
  • 3
  • 3

0 Answers0