#Error when using file: discord.Attatchment in slash commands
1 messages · Page 1 of 1 (latest)
import discord
from discord.ext import commands
from bot.sessions import PDFSession
from bot.cogs.commands.signup import signup_required
from discord import option
class AskPDF(commands.Cog):
"""
PDF session with the bot to get answers to questions from a PDF
"""
def __init__(self, bot):
self.bot = bot
@discord.slash_command(
description="Ask a question about a any PDF file (big files may take a while to process)",
)
@option(
"pdf",
discord.Attachment,
description="A file to attach to the message",
)
@option(
"question",
str,
description="The question to ask",
)
@signup_required
async def askpdf(self, ctx, file: discord.Attachment, question: str):
interaction: discord.Interaction = await ctx.respond(embed=discord.Embed(
title="Searching through the PDF...",
))
response = await PDFSession(ctx, self.bot, file).get_response(file, question)
await interaction.edit(embed=discord.Embed(
title=question,
description=response
))
?
This error is not caused by me
there must be something wrong in handling files in slash commands
You're definitely doing something wrong
also why do you do the interaction stuff if ctx.respond is already returning an interaction?
what is this? response = await PDFSession(ctx, self.bot, file).get_response(file, question)
this code is not running when the error happens
because it is doing work in the background and I want to tell the user that something is happening
is the same if you remove here the discord.Attachment?
yes I added this because I thought maybe its needed
you already using it here
I can remove all @options it does not change smt
await self.callback(self.cog, ctx, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: AskPDF.askpdf() got an unexpected keyword argument 'file'
this part is strange
why is file unexpected?
upgraded to 2.4.1 was 2.4.0 before
py-cord==2.4.1
python-dotenv==1.0.0
openai==0.27.0
PyNaCl==1.5.0
cffi==1.15.1
pycparser==2.21
gtts==2.3.1
sqlalchemy==2.0.4
alembic==1.10.2
topggpy==1.4.0
langchain==0.0.139
chromadb==0.3.21
aiofiles==23.1.0
you have topggpy installed
is this a problem?
uninstall it, same for py-cord and reinstall py-cord
is topggpy still installed?
I need this package
but I can try
still same didnt changed something
I changed the code a bit and realized somthing is really wrong with passing input args
class AskPDF(commands.Cog):
"""
PDF session with the bot to get answers to questions from a PDF
"""
def __init__(self, bot):
self.bot = bot
@discord.slash_command(description="Ask a question about a any PDF file (big files may take a while to process)")
@signup_required
async def askpdf(self, ctx, question: str):
""" Ask a question about a PDF file """
interaction: discord.Interaction = await ctx.respond(embed=discord.Embed(
title="Searching through the PDF...",
))
response = question
# response = await PDFSession(ctx, self.bot, file).get_response(file, question)
await interaction.edit(embed=discord.Embed(
title=question,
description=response
))
Got same error:
Ignoring exception in command askpdf:
Traceback (most recent call last):
File "/Users/fungus/dev/miniforge3/envs/vgpt/lib/python3.11/site-packages/discord/commands/core.py", line 124, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "/Users/fungus/dev/miniforge3/envs/vgpt/lib/python3.11/site-packages/discord/commands/core.py", line 978, in _invoke
await self.callback(self.cog, ctx, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: AskPDF.askpdf() got an unexpected keyword argument 'question'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/fungus/dev/miniforge3/envs/vgpt/lib/python3.11/site-packages/discord/bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "/Users/fungus/dev/miniforge3/envs/vgpt/lib/python3.11/site-packages/discord/commands/core.py", line 375, in invoke
await injected(ctx)
File "/Users/fungus/dev/miniforge3/envs/vgpt/lib/python3.11/site-packages/discord/commands/core.py", line 132, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: AskPDF.askpdf() got an unexpected keyword argument 'question'
what is that?
that isnt related to pycord
it is a separate library, not a fork of dpy
yea i too think this might be the issue
I just dont know what is was ^^
it is, it has discord.py in it’s dependencies.
You can use the github version of topggpy that doesn’t have discord.py in it’s dependencies.
That was also the last information I had about it
wait
only the pip one need d.py?
yes
oh makes sense. Although dpy should show up in pip list
but pip here says it is not installed
discord and discord.py are not the same
yea so? 
pretty sure they did pip uninstall discord.py
unless topggpy has discord in its requirements instead of dpy
iirc discord.py installs discord. Uninstalling discord.py does not uninstall discord
yeah they use discord
it is the other way around. discord is the mirror package for dpy.