#how would i make a button only work for the person who did the command?
1 messages · Page 1 of 1 (latest)
example?
like user: discord.Member?
view = MyView()
view.user = ctx.author
await ctx.respond(view=view)```
alright let me try
use interaction check
btw inside the command that uses the button or inside the button itself?
Thought that was obvious. The command.
thought as much just wanted to make sure
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'loginView' object has no attribute 'user'
Code
class loginView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(
label="Submit Code",
style=discord.ButtonStyle.green,
emoji="🔒",
custom_id="submit"
)
async def create(self, button: discord.ui.Button, interaction: discord.Interaction, ctx: discord.ApplicationContext):
modal = LoginModal(title="")
await interaction.response.send_modal(modal)```
Command code
@bot.slash_command()
async def command(ctx):
await ctx.defer()
view=loginView()
if view.user == ctx.author:
embed=discord.Embed(title="stuff",url='link',color=0x00aaff)
embed.add_field(name="more stuff",
value="stuff ", inline=False)
embed.set_image(url="stuff here")
embed.add_field(name="stuff here",value=f'stuff here', inline=False)
await ctx.respond(embed=embed, view=loginView())
else:
return```
if you want user in your view, you have to put user in your view
You definitely didn't understand the code I gave you
And you literally did what you wanted
You dont check the view.user in the command.
You do that on interaction_check on your view class.
Yes, this
This looks nothing like a check
What we're doing there is:
async def interaction_check(self, interaction: discord.Interaction):
view=loginView()
view.user = ctx.author```?
Creating an instance of a View(), setting an attribute to it which is the author, which then you access in your view class with self.user
And then you're sending such instance
No, that's where you run the check.
interaction_check expects a return of True or False
So you work with your condition and return whichever value.
huh?
Do you have some python knowledge
no not really
?tag lp
Official Beginner's Guide: https://wiki.python.org/moin/BeginnersGuide
Official Tutorial: https://docs.python.org/3/tutorial/
Shortcuts:
https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
https://wiki.python.org/moin/BeginnersGuide/Programmers
Learn Python:
https://automatetheboringstuff.com/ (for complete beginners to programming)
https://learnxinyminutes.com/docs/python3/ (for people who know programming already)
https://docs.python.org/3/tutorial/ (official tutorial)
http://python.swaroopch.com/ (useful book)
http://www.codeabbey.com/ (exercises for beginners)
tbh thing is my only issues are with the buttons and new stuff
async def interaction_check(self, interaction: discord.Interaction):
return interaction.user.id == view.user```
does this make sense?
so
Because an int will never be equal to a user object
async def interaction_check(self, interaction: discord.Interaction):
return interaction.user != view.user```
No
oh
Just self.user.id
like this?
You access a class attribute with self
so like this
async def interaction_check(self, interaction: discord.Interaction):
return interaction.user.id == self.user.id```
Bravo
i don't change anything in the command itself?
line 168, in interaction_check
return interaction.user.id == self.user.id
AttributeError: 'loginView' object has no attribute 'user'```
oh yeah
alright why won't this work
Command code
that happens after i press the button
@bot.slash_command()
async def command(ctx):
await ctx.defer()
view=loginView()
embed=discord.Embed(title="stuff",url='link',color=0x00aaff)
embed.add_field(name="more stuff",
value="stuff ", inline=False)
embed.set_image(url="stuff here")
embed.add_field(name="stuff here",value=f'stuff here', inline=False)
await ctx.respond(embed=embed, view=loginView())```
code so bad bro got offline
You didn't set the view attribute
And you're creating a NEW instance when sending the view
yeah but all the problems you're having are basic python issues
like this?
@bot.slash_command()
async def name(ctx):
view = loginView()```
i figured it out
dw about it