当我写命令“!LVL”时,机器人没有任何反应 大大地。这些团队曾经工作过。我改变了一些东西,现在他没有 对他们做出反应。另外,之前如果我写错了命令, 然后在控制台中机器人给出了这样的命令没有的错误 存在。现在他不响应不止一个命令,即使是 内置一个 !help
<块引用>但所有事件都正常工作。
import discord
from discord.ext import commands
from discord.utils import get
from pymongo import MongoClient
from datetime import datetime
import asyncio
import time
import os
intents = discord.Intents.default()
intents.members = True
intents.messages = True
intents.voice_states = True
intents.integrations = True
intents.invites = True
intents.presences = True
intents.webhooks = True
client = commands.Bot(command_prefix = "!", intents=intents)
cluster = MongoClient("mongodb://127.0.0.1:27017")
colluser = cluster.chill.user
collclan = cluster.chill.clans
collshop = cluster.chill.shop
@client.event
async def on_ready():
print("Bot connected to the server")
for guild in client.guilds:
for member in guild.members:
post = {
"_id": member.id,
"name": member.mention,
"user": member.name,
"inventory": [],
"warms": 0,
"mute": 0,
"voice_activ": 0,
"localban": 0,
"register": member.created_at,
"onservfrom": member.joined_at,
"clan": 0,
"marry": 0,
"love": 0,
"childs": [],
"balance": 0,
"bank": 0,
"rep": 0,
"cdxp": 0,
"cnxp": 0,
"dxp": 0,
"nxp": 0,
"cdbal": 0,
"cdlvl": 1,
"cnlvl": 1,
"dlvl": 1,
"nlvl": 1
}
if colluser.count_documents({"_id": member.id}) == 0:
colluser.insert_one(post)
@client.event
async def on_guild_role_create(role):
print("new role created")
post = {
"_id": role.id,
"titel": "none",
"cp": [],
"exp": 0,
"lvl": 0,
"maxcp": 7,
"bank": 0
}
if collclan.count_documents({"role_id": role.id}) == 0:
collclan.insert_one(post)
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.webhook_id:
return
f1 = colluser
f2 = colluser
f4 = colluser
user = message.author
data = colluser.find_one({"_id": user.id})
dtn = datetime.today().strftime("%I:%M %p")
await asyncio.sleep(1)
day = data["dxp"]
dark = data["nxp"]
dl = data["dlvl"]
nl = data["nlvl"]
balanc = data["balance"]
dexp = 500 + 100 * dl
nexp = 500 + 100 * nl
if not data["cdbal"] == "0":
return
if len(message.clean_content) >= 15:
print("Сообщение длинее 15 символов")
bal = 6
exp = 6
if len(message.clean_content) <= 14:
print("Сообщение короче 15 символов")
bal = 3
exp = 3
if any(("AM" in dtn) for AM in dtn):
print("time is AM")
colluser.update_one({"_id": user.id},
{"$set": {"dxp": + exp}})
if any(("PM" in dtn) for PM in dtn):
print("time is PM")
colluser.update_one({"_id": user.id},
{"$set": {"nxp": + exp}})
if data["dxp"] >= 500 + 100 * dl:
print(f"Новый уровень светлой стороны у пользователя {user}")
colluser.update_one({"_id": user.id},
{"$set": {"dlvl": dl + 1}})
colluser.update_one({"_id": user.id},
{"$set": {"dxp": day - dexp}})
if data["nxp"] >= 500 + 100 * nl:
print(f"Новый уровень темной стороны у пользователя {user}")
colluser.update_one({"_id": user.id},
{"$set": {"nlvl": nl + 1}})
colluser.update_one({"_id": user.id},
{"$set": {"nxp": dark - nexp}})
print(f"Пользователь {user} написал сообшение")
f1.update_one({"_id": user.id},
{"$set": {"balance": balanc + bal}})
print("F1")
f2.update_one({"_id": user.id},
{"$set": {"cdbal": "1"}})
print("F2")
await asyncio.sleep(40)
print("F3")
f4.update_one({"_id": user.id},
{"$set": {"cdbal": "0"}})
print("F4")
@client.event
async def on_voice_state_update(member, before, after):
data = colluser.find_one({"_id": member.id})
day = data["dxp"]
dark = data["nxp"]
dl = data["dlvl"]
nl = data["nlvl"]
dexp = 500 + 100 * dl
nexp = 500 + 100 * nl
guild = client.guilds[0]
guild_id = 830565202276909056
if before.channel is None and after.channel is not None:
print("1")
t1 = time.time()
colluser.update_one({"_id": member.id},
{"$set": {"voice_tim1": t1}})
elif before.channel is not None and after.channel is None:
dtn = datetime.today().strftime("%I:%M %p")
t1 = data["voice_tim1"]
voice_activ1 = data["voice_activ"]
balance = data["balance"]
t2 = time.time()
tim = t2-t1
print("0")
print(dtn)
colluser.update_one({"_id": member.id},
{"$set": {"voice_activ": voice_activ1 + tim}})
colluser.update_one({"_id": member.id},
{"$set": {"balance": balance + tim / 12}})
if any(("AM" in dtn) for AM in dtn):
print("time is AM")
colluser.update_one({"_id": member.id},
{"$set": {"dxp": day + tim / 4}})
if any(("PM" in dtn) for PM in dtn):
print("time is PM")
colluser.update_one({"_id": member.id},
{"$set": {"nxp": dark + tim / 4}})
if data["dxp"] >= 500 + 100 * dl:
colluser.update_one({"_id": member.id},
{"$set": {"dlvl": dl + 1}})
colluser.update_one({"_id": member.id},
{"$set": {"dxp": day - dexp}})
if data["nxp"] >= 500 + 100 * nl:
colluser.update_one({"_id": member.id},
{"$set": {"nlvl": nl + 1}})
colluser.update_one({"_id": member.id},
{"$set": {"nxp": dark - nexp}})
if dl >> nl:
role_id1 = 869267468047220856
role_id2 = 869267490851676200
role1 = guild.get_role(role_id1)
role2 = guild.get_role(role_id2)
await member.add_roles(role1, reason="Роль выдана за превоблодания уровня света")
await member.remove_roles(role2, reason="Роль снята за превоблодания уровня света")
if nl >> dl:
role_id1 = 869267468047220856
role_id2 = 869267490851676200
role1 = guild.get_role(role_id1)
role2 = guild.get_role(role_id2)
await member.add_roles(role2, reason="Роль выдана за превоблодания уровня тьмы")
await member.remove_roles(role1, reason="Роль снята за превоблодания уровня тьмы")
@client.event
async def on_member_join(member):
post = {
"_id": member.id,
"name": member.mention,
"user": member.name,
"inventory": [],
"warms": 0,
"mute": 0,
"voice_activ": 0,
"localban": 0,
"register": member.created_at,
"onservfrom": member.joined_at,
"clan": 0,
"marry": 0,
"love": 0,
"childs": [],
"balance": 0,
"bank": 0,
"xp": 0,
"dxp": 0,
"nxp": 0,
"cdbal": 0,
"lvl": 1,
"dlvl": 1,
"nlvl": 1
}
if colluser.count_documents({"_id": member.id}) == 0:
colluser.insert_one(post)
@client.command()
async def lvl(ctx, member: discord.Member = None):
print("test")
if member is None:
member = message.author
else:
data = colluser.find_one({"_id": member.id})
nnexp = 500 + 100 * data["nlvl"]
ndexp = 500 + 100 * data["dlvl"]
dnnexp = nnexp - data["nxp"]
dndexp = dndexp -data["dxp"]
if data["voice_activ"] >= 60:
vcm = data["voice_activ"] / 60
if vcm >= 60:
vch = vcm / 60
if vch >= 24:
vcd = vch /24
vca = vch
else:
vca = vch
t = "часов"
else:
vca = vcm
t = "минут"
else:
t = "Секунд"
vca = data["voice_activ"]
lvleb = discord.Embed(colour=role.color)
lvleb.set_author(name=f"Профиль пользователя: {member}", icon_url=member.avatar_url)
lvleb.add_field(name="Уровень света", value=data["nlvl"], inline=True)
lvleb.add_field(name="Уровень тьмы", value=data["dlvl"], inline=True)
lvleb.add_field(name="Опыт света", value=f"{data['nlvl']} / {dnnexp}", inline=True)
lvleb.add_field(name="Опыт тьмы", value=f"{data['dlvl']} / {dndexp}", inline=True)
lvleb.add_field(name="Время в войсе", value=f"{vca}{t}", inline=False)
await ctx.send(embed=lvleb)
@client.event
async def on_command_error(ctx, error):
print(error)
if isinstance(error, commands.UserInputError):
await ctx.send(embed = discord.Embed(
description = f"Правильное использование команды: `{ctx.prefix}{ctx.command.name}` ({ctx.command.brief}): `{ctx.prefix}{ctx.command.usage}`"
))
client.run("TOKEN")
答案 0 :(得分:1)
在 export const CREATE_POST_MUTATION = gql`
mutation createPost(data: CreateUserInput!) {
createPost(data: $data){
id
title
}
}
活动结束时添加 await client.process_commands(message)