【发布时间】:2021-11-03 03:44:40
【问题描述】:
我对 discord.py 比较陌生,我正在制作一个机器人,但是对于某些命令或我放置的东西,机器人会停止响应命令(当它以前工作时),我不知道如何要修复它,机器人会打开,但不响应任何命令
这是新的区域
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)
我添加的新东西是一个关卡系统,但它在某个地方出了问题
【问题讨论】:
标签: python discord.py bots