#Gettin ctx.author by using buttons

1 messages · Page 1 of 1 (latest)

ivory phoenix
#

Given the code

async def join(ctx, game_id):
    msg = await ctx.respond("test", view=ChoosingView())

How can I get the ctx.author inside the choosingView class?
For example, when I click the button, he says "Hello, fibertero"

wraith kiln
#

You can pass the author as a parameter to your view class and assign it to self

ivory phoenix
#

I tried that

proud jackal
#

interaction.user

#

In your callback you receive a discord.Interaction

#

.rtfm Interaction

proud jackal
#

Aw gawd

#

.rtfm discord.Interaction

kindred marlin
#

just take his word

proud jackal
#

Last one

kindred marlin
#

.rtfm interaction.user

somber adderBOT
kindred marlin
#

:)

ivory phoenix
#

oh

#

thanks

#

lemme try

wraith kiln
kindred marlin
wraith kiln
#

I see

kindred marlin
#

and there was a priority to just at least get it working

ivory phoenix
kindred marlin
#

what's the issue if any?

wraith kiln
#

First of all, never manually insert values to an SQL query through f strings, that's an SQL injection waiting to happen

#

second, you're trying to set player to a user object

proud jackal
#

The object becomes user#discrim if converted to a string

#

Which is what he's doing

ivory phoenix
wraith kiln
kindred marlin
#

or their nitro expires

proud jackal
#

Or they buy nitro

kindred marlin
#

or like 500 more other reasons on why their name/discriminator changes

wraith kiln
#

And currently, if their name is "; DROP TABLE game;-- your entire table is going to be deleted doggokek

ivory phoenix
#

ok the code worked

#

the bot is for me and for my friends

wraith kiln
#

That isn't an excuse to be doing bad practices

kindred marlin
#

#general message

wraith kiln
#

always use SQL parameters no matter what

ivory phoenix
#

and i don't know how to keep my database safe so i will keep it anyway

wraith kiln
#

I just told you how

ivory phoenix
#

I'll do it

#

but I thank you right away because the bot is working

wraith kiln
#

I just held a presentation about SQL injections and XSS for my colleagues last week, hopefully they learn as quickly as you do lol

tranquil kite
#

You should use ids for anything when working with a database.

#

Like Spaxter said, they could change their name, you can’t change your ID.

ivory phoenix
wraith kiln
#

Like said, there are a million ways their name/discriminator could change, so using IDs is a lot better

kindred marlin
ivory phoenix
#

thanks for all the help

#

ans sorry for my english

#

I'm brazillian

kindred marlin
#

your English was fluent

ivory phoenix
#

oh

#

nice (:

kindred marlin
#

.close

somber adderBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @vernal geyser.