Reputation: 13
I'm making a public bot in discord.py and I want to check I'm a user is an admin or not via a sqlite3 database. It returns an error shown below:
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.
Here is a portion of my code:
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
Upvotes: 1
Views: 1581
Reputation: 1
Here is the simplest way
import discord
from discord.ext import commands,tasks
bot = commands.Bot('?')
@bot.event
async def on_ready():
print("bot online")
#This will make bot online
@bot.command()
async def checkadmin(ctx,member: discord.Member=None):
#command name is checkadmin
if member is None:
member = ctx.author
#This is a command that if member is not mentioned then the member is the person who wrote the message
if member.guild_permissions.administrator:
await ctx.send("He is an Admin")
return
#This will configure that a member is an admin or not
if not member.guild_permissions.administrator:
await ctx.send("He is not an admin")
return
#This will configure that the member is not an admin
bot.run("BOT_TOKEN_HERE")
#Here paste the token for the bot
Upvotes: 0
Reputation: 11
I solved the problem this way
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)
Upvotes: 0
Reputation: 556
There's a much easier way to do this.
discord.py has a built in @commands.hasrole(role)
feature.
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
You definitely don't have to use a database or anything, as discord.py has a simple way to do this!
Upvotes: 2
Reputation: 6520
Just a hunch: rolePermissions.roleID
is an INTEGER PRIMARY KEY and y
is a string. Sqlite uses dynamic typing with one exception (from sqlite FAQ (3)):
Columns of type INTEGER PRIMARY KEY may only hold a 64-bit signed integer. An error will result if you try to put anything other than an integer into an INTEGER PRIMARY KEY column.
Upvotes: 0