#Interact get role on verify filter

1 messages · Page 1 of 1 (latest)

odd garnet
#

Hello, I am creating a verification button and I want the bot to respond by issuing a special role for participants after passing the time and message check, I am at the stage of the final part of the work and I need a little help highlighting errors before I start reinventing the wheel

class MyView(discord.ui.View): 
    @discord.ui.button(label="Verify", style=discord.ButtonStyle.primary, emoji="😎")
    async def button_callback(self, button, interaction):
        user = interaction.user
        dt1 = user.joined_at.date()
        dt2 = datetime.date.today()
        tdelta = (dt2 - dt1)
        mindate = datetime.timedelta(days=30)
        if tdelta >= mindate:
            await interaction.response.send_message(f"{user} u have {tdelta} days and u verified", ephemeral = True)
            counter = 0
            channel = bot.get_channel(806963162036699176)
            async for message in channel.history(limit = 1_000):
                if message.author == bot.user:
                   counter += 1
            if counter >= 200:
                 role = interaction.get_role(856942394862600273)
                 await user.add_role(role)
            else:
                 return 
        else:
            await interaction.response.send_message(f"{user} u have {tdelta} and cant verify for events", ephemeral = True)
        
@bot.slash_command() 
async def button(ctx):
    await ctx.respond("Click the button to verify participation in events", view=MyView()) 
whole loom
#

You could use try and except

eternal surge
odd garnet
#

@whole loom at the moment I would like to figure out how to access the role that should be issued after the message that you passed the verification

#

@eternal surge i try something things blobpain

odd garnet
#

Click button check
Time joined and and now
If days more than 30 >
Counter message
And after this i need give role

eternal surge
#

also replace 1_000 with 1000

whole loom
eternal surge
#

oh and use discord.utils.utc_now() for current datetime

whole loom
#

You can use 1_000 or 1000

eternal surge
#

oh fr?

#

nice

whole loom
#

Try it ^^

eternal surge
#

did you save the file and restart bot after the change?

odd garnet
#

On ss

#

We have logged in as LDoE Hangman#1660
version: 3.2 beta
Ignoring exception in view <MyView timeout=180.0 children=1> for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='Verify' emoji=<PartialEmoji animated=False name='😎' id=None> row=None>:
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/discord/ui/view.py", line 371, in _scheduled_task
await item.callback(interaction)
File "<string>", line 63, in button_callback
AttributeError: 'Interaction' object has no attribute 'get_role'

eternal surge
#

updated code?

odd garnet
#

Yup

eternal surge
#

no i meant show updated code

#

lol

odd garnet
#

so, if you create a delay in interaction, I think he won’t want to give out the role anyway

whole loom
#

@eternal surge

odd garnet
whole loom
#

You can even do 1_0_0_0

whole loom
#

It can be None

#

Use fetch

odd garnet
#

Seems progress doggokek

odd garnet
#

@whole loom @eternal surge TY for u helpupvote upvote upvote

#

Last problem > mass channel history kek

whole loom
#

You could delete messages after some time

odd garnet
#

I mean about 23-26 channels history doggokek

#

@whole loom
Soo many channels

odd garnet
#

anyway you were a huge help ❤️

eternal surge
odd garnet
eternal surge
#

hmm yea ig

#

.tag close

novel schoonerBOT
#

Done with your help thread?

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