本文介绍了Discord.py机器人没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对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)
我添加的新东西是水平系统,但它在某个地方出现故障
推荐答案
错误在您的on_message
事件中,因为它将命令视为正常消息来修复此问题,您只需在on_message
事件的末尾添加await self.client.process_commands(message)
这篇关于Discord.py机器人没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!