不和谐权限系统

时间:2020-04-23 09:42:49

标签: python sqlite discord discord.py

我正在discord.py中创建一个公共bot,我想通过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

4 个答案:

答案 0 :(得分:2)

有一种更简单的方法。

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具有执行此操作的简单方法!

答案 1 :(得分:0)

只是预感:expect是整数主键,StarRateIcon是字符串。 Sqlite使用动态类型带有一个异常(来自sqlite FAQ (3)):

INTEGER PRIMARY KEY类型的列只能包含一个64位带符号 整数。如果您尝试放置除 整数插入到INTEGER PRIMARY KEY列中。

答案 2 :(得分:0)

我这样解决了问题

dataframe = pd.DataFrame(pixels)   # As a dataframe with one column per color channel
column = dataframe.apply(tuple, axis=1)  # As a Series of (r,g,b) tuples

答案 3 :(得分:0)

您可以简单地使用

role = "Admin"
@commands.has_role(role)