You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
discord.ext.page : Being able to send local image in an embed from a paginator
What is the feature request for?
discord.ext.pages
The Problem
I'm trying to send a local image from my computer in an embed stored in a page from the paginator.
I've search through the entire discord.ext.pages docs and didn't even find the word "file"
The problem is I need to send multiple pictures, in one page (in two embeds of course), and also multiple pages with again multiples embeds and pages.
IF THIS IS ALREADY POSSIBLE PLEASE TEL ME SINCE I DON'T WANT TO BOTHER ANYONE
The Ideal Solution
The ideal solution would be to be able to send a picture in a normal embed type of way :
So I thought that by adding manually the file proprety into the respond function I would be able to solve the problem easily (Keep in mind I'm still in High school I'm not a 10X dev 😂)
I put the entire code here since you can copy it to see what it looks like ^^
fromdiscord.fileimportFileasyncdefrespond(
self,
interaction: discord.Interaction,
ephemeral: bool=False,
target: Optional[discord.abc.Messageable] =None,
target_message: str="Paginator sent!",
file: Optional[File] =None
) ->Union[discord.Message, discord.WebhookMessage]:
"""Sends an interaction response or followup with the paginated items. """ifnotisinstance(interaction, discord.Interaction):
raiseTypeError(f"expected Interaction not {interaction.__class__!r}")
iftargetisnotNoneandnotisinstance(target, discord.abc.Messageable):
raiseTypeError(f"expected abc.Messageable not {target.__class__!r}")
self.update_buttons()
page=self.pages[self.current_page]
page=self.get_page_content(page)
self.user=interaction.useriftarget:
iffileisNone: # I added this to check for the file and then simply copied and pasted normal thing and added file since send_message supports it.awaitinteraction.response.send_message(target_message, ephemeral=ephemeral)
else :
awaitinteraction.response.send_message(target_message, file=file, ephemeral=ephemeral)
self.message=awaittarget.send(
content=pageifisinstance(page, str) elseNone,
embeds=[] ifisinstance(page, str) elsepage,
view=self,
)
else:
ifinteraction.response.is_done():
msg=awaitinteraction.followup.send(
content=pageifisinstance(page, str) elseNone,
embeds=[] ifisinstance(page, str) elsepage,
view=self,
ephemeral=ephemeral,
)
else:
ifFileisNone :# same thing here as the change I made msg=awaitinteraction.response.send_message(
content=pageifisinstance(page, str) elseNone,
embeds=[] ifisinstance(page, str) elsepage,
view=self,
ephemeral=ephemeral,
)
else :
msg=awaitinteraction.response.send_message(
content=pageifisinstance(page, str) elseNone,
embeds=[] ifisinstance(page, str) elsepage,
view=self, file=file,
ephemeral=ephemeral
)
ifisinstance(msg, (discord.WebhookMessage, discord.Message)):
self.message=msgelifisinstance(msg, discord.Interaction):
self.message=awaitmsg.original_message()
returnself.message
Heres my code for my paginator and my pages.
But heres the problem ... it puts the image in all the pages, whether I mentioned in or not .....
So I'm putting the result :
importasyncioimportdiscordfromdiscord.commandsimportSlashCommandGroupfromdiscord.extimportcommands, pagesclassPageTest(commands.Cog):
def__init__(self, bot):
self.bot=botself.pages= [
[
discord.Embed(title=f"Vos stats :", description="En ici vous trouverais vos points de vie et autres statistiques ^^", color=0x2bff00),
discord.Embed(title=f"Votre deck", description="Appuyer le bouton dessous la carte souhaitée, ensuite il te suffira dans la page suivante de cliquer sur la case désirée !", color=0x2bff00),
],
discord.Embed(title=f"Le plateau de jeux : ", description=f"Désormais il te suffit de cliquer sur la case de ton choix !"),
discord.Embed(title=f"Le plateau de jeux : ", description=f"Désormais il te suffit de cliquer sur la case de ton choix !")
]
self.pages[0][1].set_image(
url=f"attachment://vierge_deck.jpg"
)
self.pages[2].set_image(
url=f"attachment://avatar.png"
)
defget_pages(self):
returnself.pagespagetest=SlashCommandGroup("pagetest", "Commands for testing ext.pages")
# These examples use a Slash Command Group in a cog for better organization - it's not required for using ext.pages.@pagetest.command(name="custom_buttons", guild_ids=[guild_id])asyncdefpagetest_custom_buttons(self, ctx: discord.ApplicationContext):
"""Demonstrates adding buttons to the paginator when the default buttons are not used."""paginator=pages.Paginator(
pages=self.get_pages(),
use_default_buttons=False,
loop_pages=False,
show_disabled=False,
custom_view=deck()
)
paginator.add_button(
pages.PaginatorButton(
"prev", label="<", style=discord.ButtonStyle.green, loop_label="lst"
)
)
paginator.add_button(
pages.PaginatorButton(
"page_indicator", style=discord.ButtonStyle.gray, disabled=True
)
)
paginator.add_button(
pages.PaginatorButton(
"next", style=discord.ButtonStyle.green, loop_label="fst"
)
)
paginator.add_button(
pages.PaginatorButton(
"J'ai fini pour ce tour", style=discord.ButtonStyle.red
)
)
awaitpaginator.respond(ctx.interaction, ephemeral=False, files=[discord.File(f"data/avatars/avatar.png", filename=f"avatar.png"),discord.File(f"data/cards/avatar_deck.jpg", filename=f"avatar_deck.jpg")])
defsetup(client):
client.add_cog(PageTest(client))
Additional Context
To give you a little context, I'm trying to create a card game in Discord and the pages of discord.ext.pages would allow me to make the game's gameplay more interesting ^^
Thanks in advance if you help me.
The text was updated successfully, but these errors were encountered:
Summary
discord.ext.page : Being able to send local image in an embed from a paginator
What is the feature request for?
discord.ext.pages
The Problem
I'm trying to send a local image from my computer in an embed stored in a page from the paginator.
I've search through the entire discord.ext.pages docs and didn't even find the word "file"
The problem is I need to send multiple pictures, in one page (in two embeds of course), and also multiple pages with again multiples embeds and pages.
IF THIS IS ALREADY POSSIBLE PLEASE TEL ME SINCE I DON'T WANT TO BOTHER ANYONE
The Ideal Solution
The ideal solution would be to be able to send a picture in a normal embed type of way :
Or if I have multiple images :
The Current Solution
So I thought that by adding manually the file proprety into the
respond
function I would be able to solve the problem easily (Keep in mind I'm still in High school I'm not a 10X dev 😂)I put the entire code here since you can copy it to see what it looks like ^^
Heres my code for my paginator and my pages.
But heres the problem ... it puts the image in all the pages, whether I mentioned in or not .....
So I'm putting the result :
Additional Context
To give you a little context, I'm trying to create a card game in Discord and the pages of discord.ext.pages would allow me to make the game's gameplay more interesting ^^
Thanks in advance if you help me.
The text was updated successfully, but these errors were encountered: