我正在用discord.py制作一个公共机器人,我想通过sqlite3数据库检查我是用户是管理员还是不是。它返回如下所示的错误:
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "", line 143, in permission
isadmin = conn.cursor().execute('''SELECT rp.GuildID, rp.Permission
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InterfaceError: Error binding parameter 0 - probably unsupported type.以下是我的代码的一部分:
admin = 0
while admin == 0:
for y in ctx.message.author.roles:
print(y)
isadmin = conn.cursor().execute('''SELECT rp.GuildID, rp.Permission
FROM rolePermissions AS rp
WHERE rp.roleID = ? AND rp.GuildID = ? AND rp.Permission = "Admin"''', (y, ctx.message.guild.id))
print(str(isadmin.fetchall()))
if str(isadmin.fetchone()) != "None":
admin = 1
else:
admin = 0
if admin == 1 or ctx.message.author.has_permisions(administrator=True):
print("User Is Admin")
else:
await ctx.channel.send(embed=NoPerms)
return发布于 2020-05-04 13:52:07
有一种更简单的方法可以做到这一点。
discord.py有一个内置的@commands.hasrole(role)特性。
import discord
from discord.ext import commands
role = 'rolenamegoeshere'
@bot.command(name='test', help='testing')
@commands.has_role(role)
async def test(ctx):
#stuff goes here您绝对不需要使用数据库或其他任何东西,因为discord.py有一种简单的方法可以做到这一点!
发布于 2020-04-23 23:32:38
凭直觉:rolePermissions.roleID是一个整数主键,而y是一个字符串。Sqlite使用动态类型,但有一个例外(来自sqlite FAQ (3)):
integer PRIMARY KEY类型的
列只能包含64位有符号整数。如果您尝试将整数以外的任何内容放入整数主键列中,将会出现错误。
发布于 2020-05-24 10:16:49
我用这种方法解决了这个问题
import discord
from discord.ext import commands
token = ""
client = commands.Bot(command_prefix="|")
@client.event
async def on_ready():
print("Bot is running")
@client.event
async def on_message(message):
if message.author == client.user:
pass
else:
manage_messages_permission = False
message_len = 0
while message_len < len(message.author.roles):
if discord.Permissions(message.author.roles[message_len]._permissions).manage_messages:
manage_messages_permission = True
break
else:
message_len += 1
print(manage_messages_permission)
client.run(token)https://stackoverflow.com/questions/61384081
复制相似问题