Skip to main content

Message commands extension for discord-py-interactions

Project description

interactions-message-commands

Message commands extension for discord-py-interactions

README IS NOT FINISHED YET BUT IT IS A GOOD START

Installation

pip install -U interactions-message-commands

Usage

Here is the example code for how to use message commands:

import interactions
from interactions.ext.message_commands import MessageCommands, MessageContext

bot = interactions.Client(
    token="token here"
)
cmd = MessageCommands(bot, "!")


@cmd.message()
async def ping(ctx):
    await ctx.send("pong")


@cmd.message(name="hello")
async def hi(ctx: MessageContext, name: str):
    await ctx.send(f"Hello, {name}!")


bot.start()

First, you need to initialize your client.

Next, you need to initialize MessageCommands().

  • Multiple string prefixes in a list, tuple, or set is also allowed!

Then, you need to register your message commands.

  • @cmd.message(): register a message command
    • Only keyword argument at the time is name to override function name
    • name is optional, if not specified, the function name will be used
    • In the function, ctx is required.
    • You can have as many arguments and keyword arguments as you want! *args is supported, but not **kwargs. However, *, is supported.

Finally, start the bot.

Use message commands in the Discord chat, and the bot will respond!

Example: !ping or !hello John

There is also when_mentioned() and when_mentioned_or() for the prefix:

from interactions.ext.message_commands import MessageCommands, when_mentioned_or

cmd = MessageCommands(bot, when_mentioned_or("!", "?"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interactions-message-commands-0.1.1.tar.gz (19.3 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page