I am relatively new to discord.py, I am making a bot, but with certain commands, or things that I put, the bot stops responding to the commands (when it previously worked), I can't figure out how to fix it, the bot turns on, but does not respond to any command
this is the zone where is the new
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
import urllib.request
import json
import keep_alive
import time
import asyncio
import urllib
import datetime
import pymongo
import levelsys
from discord.ext.commands import Bot
from pymongo import MongoClient
client = discord.Client()
talk_channels = []
cluster = MongoClient('mongodb+srv://endercraft46:<______>@enderbot.93khp.mongodb.net/myFirstDatabase?retryWrites=true&w=majority')
levelling = cluster["discord"]["levelling"]
bot = Bot(command_prefix="!", intents=discord.Intents.all())
async def on_ready(self):
print(f'Conectado a {self.user}')
for i in range(len(cogs)):
print(f'En linea!')
@bot.event
async def on_ready():
print('Ready')
while 1:
urllib.request.urlopen("https://Enderbotpy.endercraft26.repl.co")
await asyncio.sleep(500)
############################LEVELSYS###################################################
@commands.Cog.listener()
async def on_message(self, message):
stats = levelling.find_one({"id" : message.author.id})
if not message.author.bot:
if stats is None:
newuser = {"id" : message.author.id, "xp" : 100}
levelling.insert_one(newuser)
else:
xp = stats["xp"] + 5
levelling.update_one({"id":message.author.id}, {"$set":{"xp":xp}})
lvl = 0
while True:
if xp < ((50*(lvl**2))+(50*lvl)):
break
lvl += 1
xp -= ((50*((lvl-1)**2))+(50*(lvl-1)))
if xp == 0:
await message.channel.send(f'felicidades {message.author.mention}, subiste de nivel a **nivel: {lvl}**!')
@bot.command()
async def rank(self, ctx):
stats = levelling.find_one({"id" : ctx.author.id})
if stats is None:
embed = discord.Embed(description='no has enviado ningun mensaje, por lo tanto, no tienes rango')
await ctx.channel.send(embed=embed)
else:
xp = stats["xp"]
lvl = 0
rank = 0
while True:
if xp < ((50*(lvl**2))+(50*lvl)):
break
lvl += 1
xp -= ((50*((lvl-1)**2))+(50*(lvl-1)))
boxes = int((xp/(200**(1/2) * (lvl)))*20)
rankings = levelling.find().sort("xp",-1)
for x in rankings:
rank += 1
if stats ["id"] == x["id"]:
break
embed = discord.Embed(tittle="{}'s level stats".format(ctx.author.name))
embed.add_field(name="Name", value=ctx.author.mention, inline=True)
embed.add_field(name="XP", value=f"{xp}/{int(200*((1/2)*lvl))}")
embed.add_field(name="Rank", value=f"{rank}/{ctx.guild.member_count}")
embed.add_field(name="Progress Bar [lvl]", value=boxes * ":blue_square:" + (20-boxes) * ":white_large_square:", inline=False)
await ctx.channel.send(embed=embed)
The new thing I add is a level system, but somewhere it is giving fault