Skip to main content

Unofficial unittest extension for discord-py-interactions

Project description

About

This package allows you to test you discord bot's commands without having to run the bot itself. It is made to be a drop-in library to be used with unittest or pytest.

Installation

pip install interactions-unittest

Usage

import unittest

import interactions

import interactions_unittest as itest


@interactions.SlashCommand(
    name="ping",
    description="Replies with pong",
    options=[
        interactions.Option(
            name="extra",
            description="extra text",
            type=interactions.OptionType.STRING,
            required=False
        )
    ]
)
async def ping(ctx: interactions.SlashContext, extra: str = None):
    await ctx.send(f"Pong! {extra}")


class TestPing(unittest.IsolatedAsyncioTestCase):
    async def test_ping(self):
        actions = await itest.call_slash(ping, extra="extra text")
        self.assertTrue(actions[0]["action"] == "send")
        self.assertTrue(actions[0]["message"]["content"] == "Pong! extra text")

Documentation

The call_slash method allows you to call a slash command with arguments, it will return a list of action dicts.

Each action dict has the following keys:

  • action: The action that was performed, ex: send, edit, delete, defer
  • message: The message that was sent, edited or deleted

Features

  • context.edit message
  • context.delete message
  • context.send message
  • context.defer
  • message.delete
  • message.edit
  • message.reply
  • message.react
  • extensions

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_unittest-1.0.3.tar.gz (17.3 kB view hashes)

Uploaded Source

Built Distribution

interactions_unittest-1.0.3-py3-none-any.whl (17.3 kB view hashes)

Uploaded Python 3

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