【发布时间】:2021-02-25 01:14:51
【问题描述】:
db = sqlite3.connect("BlacklistedUsers.db")
c = db.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS "BlacklistedUser_IDs" (
"User_IDs" INTEGER,
"Reason" TEXT,
PRIMARY KEY("User_IDs")
);''')
def owner_ID(ctx):
return ctx.author.id == 738332946934661132
def not_allowed(ctx):
member = ctx.discord.member.id
c.execute("SELECT `User_IDs` FROM `BlacklistedUser_IDs` WHERE `User_IDs`=%s", (member))
UserID = cursor.fetchall()
if ctx.author.id not in UserID:
print(UserID)
return True
else:
return False
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CheckFailure):
embed = discord.Embed(title="", description="", colour=discord.Color.red())
embed.set_author(name="BlackListed!")
embed.add_field(name="Sorry", value=f"{ctx.author} It looks like you've been Blacklisted! for {Reason}", inline=False)
embed.add_field(name="If you would like to Appeal Or think this might have been a mistake Message", value="@L Y N X", inline=False)
await ctx.send(embed=embed)
@bot.command()
@commands.check(owner_ID)
async def blacklist(ctx, member: discord.Member, *, reason=None):
c.execute("INSERT INTO `BlacklistedUser_IDs`(User_IDs, Reason) VALUES(%s, %s)", (member.id, reason))
db.commit()
embed = discord.Embed(title="", description="", colour=discord.Color.red())
embed.set_author(name="Blacklisted!")
embed.add_field(name="Success", value=f"{member.name}#{member.discriminator} -- {member.id} Has been Blacklisted from Using commands!")
embed.add_field(name="Reason : ", value=f"{reason}")
await ctx.send(embed=embed)
@bot.command()
@commands.check(owner_ID)
async def unblacklist(ctx, member: discord.Member):
c.execute("DELETE FROM BlacklistedUser_IDs WHERE User_IDs =%s AND Reason=%s;", (member.id, reason))
db.commit()
embed = discord.Embed(title="", description="", colour=discord.Color.red())
embed.set_author(name="Unblacklisted!")
embed.add_field(name="Success", value=f"{member.name}#{member.discriminator} -- {member.id} Has been Unblacklisted from Using commands!")
await ctx.send(embed=embed)
当尝试运行此命令时,它不会运行 Fullstop.. 它会运行 SQL 之上的任何内容,但是当涉及到 SQL 时,它不会运行,无论是黑名单还是非黑名单?一切看起来都是正确的,所以我对出了什么问题感到困惑..
任何解决方案 // 问题修复?
【问题讨论】:
-
“它不会运行”是什么意思?有错误吗?脚本会停止吗?如果可以,请提供更多详细信息
-
我运行该命令,但它会停止并且不会在命令代码中运行任何内容,
c.execute以上的任何内容都会运行,但c.execute似乎是 1) 破坏整个代码,2)不起作用,它不会将任何东西放入数据库或任何东西,这让我感到困惑,因为它看起来正确,但 SQL 似乎打破了这一点..
标签: python database sqlite discord discord.py-rewrite