Discord bot, show persistent button on User status changed

58 views Asked by At

I am trying to have a button displayed in a specific channel. I know very well how to handle that using the commands, but I need this to be automatic, where users don't have to enter any command. Ideally there is a channel where nobody can send messages, but only persistent/static buttons live. I tried hooking up this to the bot.event on_presence_update, which gets called, but no button is being presented. No errors either. Will be greatly thankful for any way to do it, regardless of the method, as long as users don't have to use any commands. Button/s need to show both for existing users and anyone that joins the server after. Here is the code I've tried the latest:

class MyView(View):

    def __init__(self):
        super().__init__(timeout=None)
        

    @discord.ui.button(
        label = "Invite Link",
        style = discord.ButtonStyle.blurple,
        custom_id="Test",
        emoji="",
        )
    async def button_callback(self, interaction, button):
        button.label = "Changed Label!"
        await interaction.response.edit_message(view=self)

@bot.event
async def on_presence_update(before, after):
    print("user update detected")
    if after.status.name == 'online':
        await bot.get_channel(1111111111111111111).send('Hello')
        
        button1 = MyButton(
            label = "Danger!",
            style = discord.ButtonStyle.danger,
            custom_id="Test",
            emoji="",
        )
        view = MyView()
        view.add_item(button1)
        bot.add_view(view)

bot.run(TOKEN)

Thanks!

0

There are 0 answers