# Discord module

The Discord module is an importable module that allows you to interact with Discord. To use it, import it like this:

```lua
local d = require('discord');
d.send("Hello world!")
```

## send(message: string)

Sends a text message in Discord. You can send up to 5 messages per custom function. You can also use this to mention people, but @everyone and @here and mentioning roles will not work.

```lua
local d = require('discord');
d.send("Hello, <@"..message.author.id..">!")
-- Responds: Hello @Big P!
```

## run(command: string)

Runs an OcelotBOT command as if the user running the custom function had run it. The command is run in the context of the triggering message, as if the user that triggered the function and will send the output into the channel. Some commands can't be run inside a custom command, and some commands may not act as expected.&#x20;

{% hint style="info" %}
**Commands do not have to contain the prefix to work**, including the prefix will still work but if you change the prefix after the fact the custom command will need to be updated.
{% endhint %}

```lua
local d = require('discord');
d.run("8ball am I running inside a custom command?")
```

## runWithSettings(command: string, settings: table)

Runs an OcelotBOT command with specific settings. This is an advanced function that will allow you to customise OcelotBOT command responses beyond what is possible normally. For a list of possible uses, check the [Command Settings ](/custom-commands/discord-module/command-settings.md)page.

```lua
local d = require('discord');
-- Displays the 5th page from the command !reddit aww and disabled the page buttons
d.runWithSettings("!reddit aww", {["pagination.page"]=5,["pagination.disabled"]=1})
```

## playAudio(url: string)

Plays a single audio track, can be a YouTube URL or any audio file or stream. Can always be stopped with !music stop, and will not interrupt currently playing music or guessing games. Joins the voice channel the triggering user is in.

```lua
local d = require('discord');
d.playAudio("https://www.youtube.com/watch?v=_htnaGN8eOs");
```

## paginate(pages: string\[])

Paginate uses OcelotBOT's standard reaction-based pagination, to display each page in `pages` as a separate message.&#x20;

```lua
local d = require('discord');
d.paginate({"This is page 1", "This is page 2", "This is page 3"})
```

## react(emoji: string)

Reacts to the trigger message with the specified emoji ID.

To get the emoji ID, type a backslash (\\) then the emoji you want and send it in Discord. You will see something like this: <:yikes:813555460598267924> &#x20;

&#x20;The ID is the number, so "813555460598267924" in this case.&#x20;

```lua
local d = require('discord');
d.react("813555460598267924"); -- The yikes emoji from above
```

## webhook(message: string, username: string, avatar: string)

Allows you to send a message as a webhook, with a specific username and avatar.&#x20;

```lua
local d = require('discord');
d.webhook("Identity theft is not a joke", message.author.username, message.author.avatar);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ocelotbot.xyz/custom-commands/discord-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
