Skip to content

Pilot1782/interactions_unittest

Repository files navigation

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_type == itest.ActionType.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 actions. The call_component method allows you to call a component interaction, it will return a list of actions. The call_autocomplete method allows you to call an autocomplete interaction, it will return a list of actions.

Each action has an action_type attribute that can be used to determine the type of action an a creation_time attribute that can be used to determine the order of the actions. For each action there is a subclass containing the data of the action.

Features

  • context.edit message
  • context.delete message
  • context.send message
  • context.defer
  • context.send_modal
  • channel.get_message
  • channel.delete_message
  • component interaction
  • autocomplete interaction
  • message.delete
  • message.edit
  • message.reply
  • message.react
  • extensions

TODO

  • Add more examples

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages