Recently, I was experimenting with persistent views and found out that only 1 instance can exist in memory. Consider this example:
class AutoroleView(discord.ui.View):
def __init__(self, role_id=None, *args, **kwargs):
super().__init__(*args, **kwargs, timeout=None)
self.role_id = role_id
@discord.ui.button(label="Вывести", custom_id="ar-button")
async def button_callback(self, button, interaction: discord.Interaction):
await interaction.response.send_message(f"{self.role_id=}")
This is a basic view that stores role_id inside it and displays it on button click. If I would send 2 views in one channel with first having role_id=15 and second role_id=17 it doesn't matter which button i'll press - it will display me that role_id is equal to 17. (latest value I suppose)
I want to create a persistent view that will give people roles based on their selection in select menu. The bot can possibly be on multiple servers. Will this mean that this persistent view will give SAME roles on DIFFERENT servers?
Also, after restart, if I press the button once again, it will show me that role_id is not set. I guess it's because I'm initializing it this way:
@bot.event
async def on_ready():
bot.add_view(AutoroleView())
print("Bot is ready")