### Basic Paginator Setup Source: https://docs.pycord.dev/en/master/ext/pages/index.html Demonstrates the basic usage of the Paginator class with a list of pages. This is the simplest way to get started with pagination. ```python import asyncio import discord from discord.commands import SlashCommandGroup from discord.ext import commands, pages class PageTest(commands.Cog): def __init__(self, bot): self.bot = bot self.pages = [ "Page 1", [ discord.Embed(title="Page 2, Embed 1"), discord.Embed(title="Page 2, Embed 2"), ], "Page Three", discord.Embed(title="Page Four"), discord.Embed(title="Page Five"), [ discord.Embed(title="Page Six, Embed 1"), discord.Embed(title="Page Seven, Embed 2"), ], ] self.pages[3].set_image( url="https://c.tenor.com/pPKOYQpTO8AAAAAM/monkey-developer.gif" ) self.pages[4].add_field( name="Example Field", value="Example Value", inline=False ) self.pages[4].add_field( name="Another Example Field", value="Another Example Value", inline=False ) self.more_pages = [ "Second Page One", discord.Embed(title="Second Page Two"), discord.Embed(title="Second Page Three"), ] self.even_more_pages = ["11111", "22222", "33333"] def get_pages(self): return self.pages pagetest = SlashCommandGroup("pagetest", "Commands for testing ext.pages") # These examples use a Slash Command Group in a cog for better organization - it's not required for using ext.pages. @pagetest.command(name="default") async def pagetest_default(self, ctx: discord.ApplicationContext): """Demonstrates using the paginator with the default options.""" paginator = pages.Paginator(pages=self.get_pages()) await paginator.respond(ctx.interaction, ephemeral=False) ``` -------------------------------- ### Custom Sink Implementation Example Source: https://docs.pycord.dev/en/master/api/sinks.html Demonstrates how to subclass the core Sink class for custom audio recording storage. Replace the example with your custom sink class when starting a recording. ```python vc.start_recording( MySubClassedSink(), finished_callback, ctx.channel, ) ``` -------------------------------- ### Create a Simple Extension with a Command Source: https://docs.pycord.dev/en/master/ext/commands/extensions.html An extension is a Python file with a `setup` function that takes the bot instance. This example defines a command and adds it to the bot upon loading. ```python from discord.ext import commands @commands.command() async def hello(ctx): await ctx.send(f'Hello {ctx.author.display_name}.') def setup(bot): bot.add_command(hello) ``` -------------------------------- ### Start Listening from Store Source: https://docs.pycord.dev/en/master/_modules/discord/ui/view.html Initializes the view's listening process from a store, setting up the cancel callback and starting the timeout task if a timeout is defined. ```python def _start_listening_from_store(self, store: ViewStore) -> None: self._cancel_callback = partial(store.remove_view) if self.timeout: loop = asyncio.get_running_loop() if self._timeout_task is not None: self._timeout_task.cancel() self._timeout_expiry = time.monotonic() + self.timeout self._timeout_task = loop.create_task(self._timeout_task_impl()) ``` -------------------------------- ### Task Waiting for Bot Ready Source: https://docs.pycord.dev/en/master/ext/tasks/index.html This example shows how to ensure a background task only starts after the bot has successfully connected and is ready. The `before_loop` decorator is used to implement this waiting logic. ```python from discord.ext import tasks, commands class MyCog(commands.Cog): def __init__(self, bot): self.index = 0 self.bot = bot self.printer.start() def cog_unload(self): self.printer.cancel() @tasks.loop(seconds=5.0) async def printer(self): print(self.index) self.index += 1 @printer.before_loop async def before_printer(self): print('waiting...') await self.bot.wait_until_ready() ``` -------------------------------- ### NoEntryPointError Source: https://docs.pycord.dev/en/master/_modules/discord/errors.html Raised when an extension does not have a `setup` entry point function. ```APIDOC class NoEntryPointError(ExtensionError): """An exception raised when an extension does not have a ``setup`` entry point function. This inherits from :exc:`ExtensionError` """ def __init__(self, name: str) -> None: super().__init__(f"Extension {name!r} has no 'setup' function.", name=name) ``` -------------------------------- ### start(token, reconnect=True) Source: https://docs.pycord.dev/en/master/_modules/discord/client.html A shorthand coroutine that combines logging in with starting the connection to Discord. It first calls `login` with the provided token and then calls `connect` to establish the WebSocket connection. ```APIDOC ## start(token, reconnect=True) ### Description A shorthand coroutine for :meth:`login` + :meth:`connect`. ### Method `async def start(token: str, *, reconnect: bool = True) -> None` ### Parameters - **token** (str) - The token to log in with. - **reconnect** (bool) - Optional. Whether to attempt to reconnect if the connection is lost. Defaults to True. ### Returns None ### Raises - **TypeError**: An unexpected keyword argument was received. ``` -------------------------------- ### Get Help Command Opening Note Source: https://docs.pycord.dev/en/master/_modules/discord/ext/commands/help.html Returns the help command's opening note, useful for overriding for i18n purposes. The default implementation provides instructions on how to get more info on commands and categories. ```python def get_opening_note(self): """Returns help command's opening note. This is mainly useful to override for i18n purposes. The default implementation returns :: Use `{prefix}{command_name} [command]` for more info on a command. You can also use `{prefix}{command_name} [category]` for more info on a category. Returns ------- :class:`str` The help command opening note. """ command_name = self.invoked_with return ( f"Use `{self.context.clean_prefix}{command_name} [command]` for more info" " on a command.\nYou can also use" f" `{self.context.clean_prefix}{command_name} [category]` for more info on" " a category." ) ``` -------------------------------- ### Get Onboarding Flow Source: https://docs.pycord.dev/en/master/api/models.html Returns the onboarding flow for the guild. ```APIDOC ## Get Onboarding Flow ### Description Returns the `Onboarding` flow for the guild. Added in version 2.5. ### Method GET ### Endpoint `/guild/{guild_id}/onboarding` ### Response #### Success Response (200) - **onboarding** (`Onboarding`) - The onboarding flow for the guild. #### Response Example ```json { "prompts": [ { "type": "multiple_choice", "options": [ { "title": "What are you interested in?", "emoji_id": null, "emoji_name": null } ], "title": "What brings you here?", "single_select": false } ], "default_channels": ["1122334455"] } ``` ``` -------------------------------- ### start_recording Source: https://docs.pycord.dev/en/master/_modules/discord/voice/client.html Starts recording audio from the connected voice channel to a specified sink. ```APIDOC ## start_recording Start recording the audio from the current connected channel to the provided sink. .. versionadded:: 2.0 .. warning:: Recording may not work as expected due to the new DAVE (End-to-End Encryption) for voice calls. ### Parameters - **sink**: Sink - A Sink in which all audio packets will be processed in. - **callback**: Optional[AfterCallback] - A callback function to be called after recording stops or an error occurs. - **sync_start**: bool - If True, the recording will start synchronously. Defaults to MISSING. ``` -------------------------------- ### prepare_help_command Source: https://docs.pycord.dev/en/master/_modules/discord/ext/commands/help.html Clears the paginator and performs initial setup before a help command is processed. ```APIDOC async def prepare_help_command(self, ctx, command): self.paginator.clear() await super().prepare_help_command(ctx, command) ``` -------------------------------- ### Get Game Start Timestamp Source: https://docs.pycord.dev/en/master/_modules/discord/activity.html Returns the datetime when the user started playing the game, in UTC. Returns None if the start timestamp is not set. ```python def start(self) -> datetime.datetime | None: """When the user started playing this game in UTC, if applicable.""" if self._start: return datetime.datetime.fromtimestamp( self._start / 1000, tz=datetime.timezone.utc ) return None ``` -------------------------------- ### get_ending_note Source: https://docs.pycord.dev/en/master/_modules/discord/ext/commands/help.html Returns the ending note for the help command, which typically guides users on how to get more information. ```APIDOC def get_ending_note(self) -> str: """Returns help command's ending note. This is mainly useful to override for i18n purposes.""" command_name = self.invoked_with return ( f"Type {self.context.clean_prefix}{command_name} command for more info on a" " command.\n You can also type" f" {self.context.clean_prefix}{command_name} category for more info on a" " category." ) ``` -------------------------------- ### BotBase initialization Source: https://docs.pycord.dev/en/master/_modules/discord/ext/commands/bot.html Initializes the BotBase class, setting up command prefix and help command. The command prefix can be a string, an iterable of strings, or a callable that returns a string or iterable of strings. The help command defaults to `DefaultHelpCommand` if not provided. ```python def __init__( self, command_prefix: ( str | Iterable[str] | Callable[ [Bot | AutoShardedBot, Message], str | Iterable[str] | Coroutine[Any, Any, str | Iterable[str]], ] ) = when_mentioned, help_command: HelpCommand | None = MISSING, **options, ): super().__init__(**options) self.command_prefix = command_prefix self.help_command = ( DefaultHelpCommand() if help_command is MISSING else help_command ) self.strip_after_prefix = options.get("strip_after_prefix", False) ``` -------------------------------- ### Basic Logging Configuration Source: https://docs.pycord.dev/en/master/logging.html Configure the logging module to output logs to the console. This is a simple setup that can be placed at the start of your application. ```python import logging logging.basicConfig(level=logging.INFO) ``` -------------------------------- ### before_invoke Decorator Example Source: https://docs.pycord.dev/en/master/_modules/discord/ext/commands/core.html Registers a coroutine to be executed before a command is invoked. This can be used for logging or setup tasks across multiple commands or cogs. ```python async def record_usage(ctx): print(ctx.author, 'used', ctx.command, 'at', ctx.message.created_at) @bot.command() @commands.before_invoke(record_usage) async def who(ctx): # Output: used who at