Discord.py-从数据库获取类别的ID
所以我试图让我的机器人创建一个文本频道,每次我对一条消息做出反应时都在一个类别内,有点像一个票据机器人 我当前收到错误Discord.py-从数据库获取类别的ID,discord.py,discord.py-rewrite,Discord.py,Discord.py Rewrite,所以我试图让我的机器人创建一个文本频道,每次我对一条消息做出反应时都在一个类别内,有点像一个票据机器人 我当前收到错误AttributeError:'int'对象没有属性“id”,因为当我从数据库中获取id时,它会变成一个元组,并且guild。创建文本频道('name'category=category)(category部分)只接受整数 以下是该命令的全部代码: emojis = ['\U0001F4E9', '\U000023EF'] class Changelog(commands.C
AttributeError:'int'对象没有属性“id”
,因为当我从数据库中获取id时,它会变成一个元组,并且guild。创建文本频道('name'category=category)
(category部分)只接受整数
以下是该命令的全部代码:
emojis = ['\U0001F4E9', '\U000023EF']
class Changelog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print('Application is loaded')
@commands.group(invoke_without_command=True)
async def application(self, ctx):
embed = discord.Embed(title="Application Commands",
description="Channel: <#channel>", color=0)
await ctx.send(embed=embed)
@application.command()
async def channel(self, ctx, channel: discord.TextChannel):
if ctx.message.author.guild_permissions.administrator:
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(
f'SELECT channel_id FROM application WHERE guild_id = {ctx.guild.id}')
result = cursor.fetchone()
if result is None:
sql = ('INSERT INTO application(guild_id, channel_id) VALUES(?,?)')
val = (ctx.guild.id, channel.id)
await ctx.send(f'Message has been sent and channel has been set to {channel.mention}')
elif result is not None:
sql = ('UPDATE application SET channel_id = ? WHERE guild_id = ?')
val = (channel.id, ctx.guild.id)
await ctx.send(f'Message has been sent and channel has been updated to {channel.mention}')
cursor.execute(sql, val)
db.commit()
youtube = ':play_pause:'
staff = ':envelope_with_arrow:'
embed = discord.Embed(title="ReefCraft Applications", color=0)
embed.add_field(
name="** **", value=f"{youtube} YouTube Application\n\n{staff} Staff Application", inline=False)
embed.add_field(name="\n\nInformation",
value="Reacting to one of the emotes will create a new text-channel, where you will write your applicaiton!")
reaction_message = await channel.send(embed=embed)
for emoji in emojis:
await reaction_message.add_reaction(emoji)
cursor.execute(
f'SELECT category_id FROM application WHERE guild_id = {ctx.guild.id}')
category_result = cursor.fetchone()
category = await ctx.guild.create_category('Applications')
if category_result is None:
sqql = (
'INSERT INTO application(guild_id, category_id) VALUES(?, ?)')
values = (ctx.guild.id, category.id)
await ctx.send(f'Category has been set to {category.id}')
if category_result is not None:
sqql = (
'UPDATE application SET category_id = ? WHERE guild_id = ?')
values = (category.id, ctx.guild.id)
await ctx.send(f'Category has been updated to {category.id}')
cursor.execute(sqql, values)
db.commit()
cursor.close()
db.close()
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
emoji = reaction.emoji
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(f'SELECT channel_id FROM application WHERE 1')
channel = cursor.fetchone()
channel_id = self.client.get_channel(int(channel[0]))
cursor.execute('SELECT category_id FROM application WHERE 1')
category = cursor.fetchone()
category_id = int(category[0])
guild = user.guild
if user.bot:
return
if emoji == "\U0001F4E9":
await channel_id.send("You clicked the Staff Application")
await guild.create_text_channel("Staff", category=category_id)
elif emoji == "\U000023EF":
await channel_id.send("You clicked the Youtube Application")
else:
return
def setup(client):
client.add_cog(Changelog(client))
emojis=['\U0001F4E9','\U000023EF']
类更改日志(commands.Cog):
定义初始化(自我,客户机):
self.client=client
@commands.Cog.listener()
异步def on_就绪(自):
打印('应用程序已加载')
@commands.group(调用\u而不调用\u command=True)
异步def应用程序(自身、ctx):
嵌入=discord.embed(title=“应用程序命令”,
description=“频道:”,颜色=0)
等待ctx.send(嵌入=嵌入)
@application.command()
异步def通道(自、ctx、通道:discord.TextChannel):
如果ctx.message.author.guild\u permissions.administrator:
db=sqlite3.connect('main.sqlite')
cursor=db.cursor()
cursor.execute(
f'SELECT channel_id FROM application WHERE guild_id={ctx.guild.id}')
结果=cursor.fetchone()
如果结果为无:
sql=(“插入应用程序(公会id、频道id)值(?,)”
val=(ctx.guild.id,channel.id)
wait ctx.send(f'消息已发送,通道已设置为{channel.antify}')
elif结果不是无:
sql=('UPDATE application SET channel_id=?WHERE guild_id=?'))
val=(channel.id,ctx.guild.id)
wait ctx.send(f'消息已发送,频道已更新为{channel.antify}')
cursor.execute(sql,val)
db.commit()
youtube=':播放\暂停:'
staff=':带有箭头的信封'
嵌入=discord.embed(title=“ReefCraft应用程序”,颜色=0)
embed.add_字段(
name=“**”,value=f“{youtube}youtube应用程序\n\n{staff}staff应用程序”,inline=False)
embed.add_字段(name=“\n\n信息”,
value=“对其中一个表情做出反应将创建一个新的文本频道,您将在其中编写应用程序!”)
反应\消息=等待通道。发送(嵌入=嵌入)
对于表情符号中的表情符号:
等待反应信息。添加反应(表情符号)
cursor.execute(
f'SELECT category_id FROM application WHERE guild_id={ctx.guild.id}')
category_result=cursor.fetchone()
category=wait ctx.guild.create_category('应用程序')
如果类别_结果为无:
sqql=(
'插入应用程序(公会id、类别id)值(?,)')
值=(ctx.guild.id,category.id)
wait ctx.send(f'Category已设置为{Category.id}')
如果类别_结果不是无:
sqql=(
“更新应用程序集类别\u id=?其中\u id=?”)
值=(category.id,ctx.guild.id)
wait ctx.send(f'Category已更新为{Category.id}')
cursor.execute(sqql,值)
db.commit()
cursor.close()
db.close()
@commands.Cog.listener()
添加(自身、反应、用户)时的异步定义:
表情符号
db=sqlite3.connect('main.sqlite')
cursor=db.cursor()
cursor.execute(f'SELECT channel_id FROM application WHERE 1')
channel=cursor.fetchone()
channel_id=self.client.get_channel(int(channel[0]))
cursor.execute('SELECT category\u id FROM application WHERE 1')
category=cursor.fetchone()
类别id=int(类别[0])
guild=user.guild
如果user.bot:
返回
如果表情符号==“\U0001F4E9”:
等待频道id.send(“您单击了员工应用程序”)
等待公会。创建文字频道(“工作人员”,类别=类别id)
elif表情符号==“\U000023EF”:
等待频道id.send(“您点击了Youtube应用程序”)
其他:
返回
def设置(客户端):
客户机。添加_cog(变更日志(客户机))