@Chispy

Что тут не так?

Вопрос на засыпку.
Бот говорит что пользователь в группе Testy хотя база данных говорит об обратном что пользователь уже в группе None и его можно пропустить.606b63020350e957518421.jpeg606b630c53dac931554036.jpeg

Код:
@commands.command()
	async def create(self, ctx, *, name):
		id = ctx.author.id
		cur.execute(f"SELECT id FROM users WHERE id = {ctx.author.id}")
		if cur.fetchone() == None:
			db = discord.Embed(
			title = "Вас нету в базе данных...",
			color = discord.Color.red()
			)
			await ctx.reply(embed = db)
		else:
			cur.execute(f"SELECT fractionName FROM users WHERE id = {id}")
			if str(cur.fetchone()[0]) != "None":
				have = discord.Embed(
				title = "Вы уже в фракции...",
				color = discord.Color.red()
				)
			else:
				with open(os.path.join("settings", "max.txt"), "r") as r:
					fracMax = r.read()
				cur.execute("SELECT MAX(fracID) FROM fractions")
				new = cur.fetchone()[0]
				now = int(new) + 1
				if int(now) > int(fracMax):
					freck = discord.Embed(
					title = "Ваша фракция не модет быть создана.",
					color = discord.Color.red()
					)
					freck.set_footer(text = "Код ошибки: 001")
					await ctx.reply(embed = freck)
				else:
					cur.execute(f"SELECT createBan FROM users WHERE id = {id}")
					if int(cur.fetchone()[0])== 1:
						freck = discord.Embed(
					title = "Ваша фракция не модет быть создана.",
					color = discord.Color.red()
					)
						freck.set_footer(text = "Код ошибки: 002")
						await ctx.reply(embed = freck)
					else:
						creating = discord.Embed(
						title = "Создаëм!",
						description = "Это займëт время...",
						color = discord.Color.blue()
						)
						msg = await ctx.reply(embed = creating)
						guild = ctx.author.guild
						category = await guild.create_category(name = name)
						await category.set_permissions(guild.default_role, view_channel = False)
						fracRole = await guild.create_role(name = name)
						await category.set_permissions(fracRole, view_channel = True)
						await guild.create_text_channel(name = f"Главный чат {name}", category = category)
						await guild.create_voice_channel(name = "Основной", category = category)
						await ctx.author.add_roles(fracRole)
						leaderRole = discord.utils.get(guild.roles, id = 824545035189223434)
						await ctx.author.add_roles(leaderRole)
						done = discord.Embed(
						title = "Готово.",
						color = discord.Color.green()
						)
						cur.execute(f"INSERT INTO fractions(name, leader, fracID) VALUES('{name}', {ctx.author.id}, {now})")
						con.commit()
						cur.execute(f"UPDATE users SET fractionName = '{name}' WHERE id = {ctx.author.id}")
						con.commit()
						await msg.edit(embed = done)
	
	@commands.command()
	@commands.has_role(824545035189223434)
	async def search(self, ctx, ToMax: int = 1):
		if ToMax > 5:
			ToHigh = discord.Embed(
			title = f"Нельзя вести набор на {ToMax} человек. Максимум 5",
			color = discord.Color.red()
			)
			await ctx.reply(embed = ToHigh)
		else:
			people = 0
			cur.execute(f"SELECT name FROM fractions WHERE leader = {ctx.author.id}")
			fracName = cur.fetchone()[0]
			new = discord.Embed(
			title = f"Набор в {fracName}",
			description = f"{ctx.author.mention} набирает людей в {fracName}.\n\n?{fracName}\n{people}/{ToMax}",
			color = discord.Color.blue()
			)
			fmash = await self.client.get_channel(id = 824704189313318953).send(embed = new)
			while True:
				if people == ToMax:
					em = discord.Embed(
					title = "Набор окончен..."
					)
					await fmash.edit(embed = em)
				else:
					msg = await self.client.wait_for("message")
					if msg.content == f"?{fracName}":
						if msg.author == ctx.author:
							denied = discord.Embed(
							title = "Вы не можете этого",
							color = discord.Color.red()
							)
							await msg.reply(embed = denied)
						else:
							if 2 == 1:
								print("Bug")
							else:
								cur.execute(f"SELECT id FROM users WHERE id = {msg.author.id}")
								if cur.fetchone() == None:
									db = discord.Embed(
									title = "Вас нету в базе данных...",
									color = discord.Color.red()
									)
									await msg.reply(embed = db)
								else:
									cur.execute(f"SELECT fractionName FROM users WHERE id = {ctx.author.id}")
									ha = cur.fetchone()[0]
									print(ha)
									if str(ha) == "None":
										cur.execute(f"UPDATE users SET fractionName = '{fracName}' WHERE id = {msg.author.id}")
										con.commit()
										role = discord.utils.get(ctx.author.guild.roles, name = fracName)
										await msg.author.add_roles(role)
										done = discord.Embed(
										title = "Готово...",
										color = discord.Color.green()
										)
										await msg.reply(embed = done)
										people += 1
									else:
										have = discord.Embed(
										title = "Вы уже во фракции",
										color = discord.Color.red()
										)
										await msg.reply(embed = have)
	
	@commands.command()
	async def leave(self, ctx):
		cur.execute(f"SELECT fractionName FROM users WHERE id = {ctx.author.id}")
		fracName = cur.fetchone()[0]
		if str(fracName) == 'None':
			denied = discord.Embed(
			title = "Вы не в фракции.",
			color = discord.Color.red()
			)
			await ctx.reply(embed = denied)
		else:
			cur.execute(f"SELECT name FROM fractions WHERE leader = {ctx.author.id}")
			if str(cur.fetchone()) == 'None':
				cur.execute(f"UPDATE users SET fractionName = None WHERE id = {ctx.author.id}")
				con.commit()
				nae = fracName[0]
				r= discord.utils.get(ctx.author.guild.roles, name = nae)
#				await ctx.author.remove_roles(r)
				done = discord.Embed(
				title = "Готово.",
				color = discord.Color.green()
				)
				await ctx.reply(embed = done)
			else:
				denied = discord.Embed(
				title = "Вы лидер фракции и вы не можете еë покинуть.",
				color = discord.Color.red()
				)
				await ctx.reply(embed = denied)
  • Вопрос задан
  • 157 просмотров
Решения вопроса 1
@mkone112
Начинающий питонист.
Почисти код, читать эту кашу физически больно. Особенно это улыбнуло:
if 2 == 1:
  print("Bug")
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы