mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-18 23:15:48 +00:00
Change persistent view example to use new setup_hook
This commit is contained in:
parent
c95c163266
commit
bc70ec5cfd
@ -33,20 +33,18 @@ class PersistentViewBot(commands.Bot):
|
||||
def __init__(self):
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'), intents=intents)
|
||||
self.persistent_views_added = False
|
||||
|
||||
async def setup_hook(self) -> None:
|
||||
# Register the persistent view for listening here.
|
||||
# Note that this does not send the view to any message.
|
||||
# In order to do this you need to first send a message with the View, which is shown below.
|
||||
# If you have the message_id you can also pass it as a keyword argument, but for this example
|
||||
# we don't have one.
|
||||
self.add_view(PersistentView())
|
||||
|
||||
async def on_ready(self):
|
||||
if not self.persistent_views_added:
|
||||
# Register the persistent view for listening here.
|
||||
# Note that this does not send the view to any message.
|
||||
# In order to do this you need to first send a message with the View, which is shown below.
|
||||
# If you have the message_id you can also pass it as a keyword argument, but for this example
|
||||
# we don't have one.
|
||||
self.add_view(PersistentView())
|
||||
self.persistent_views_added = True
|
||||
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
print('------')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user