update guides
This commit is contained in:
@@ -9,14 +9,13 @@ slug: sending-messages
|
|||||||
You can send messages via Reacord to a channel like so.
|
You can send messages via Reacord to a channel like so.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
const channelId = "abc123deadbeef"
|
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
reacord.send(channelId, "Hello, world!")
|
const channel = await client.channels.fetch("abc123deadbeef")
|
||||||
|
reacord.createChannelMessage(channel, {}, "Hello, world!")
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
The `.send()` function creates a **Reacord instance**. You can pass strings, numbers, or anything that can be rendered by React, such as JSX!
|
The `.createChannelMessage()` function creates a **Reacord instance**. You can pass strings, numbers, or anything that can be rendered by React, such as JSX!
|
||||||
|
|
||||||
Components rendered through this instance can include state and effects, and the message on Discord will update automatically.
|
Components rendered through this instance can include state and effects, and the message on Discord will update automatically.
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ function Uptime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
reacord.send(channelId, <Uptime />)
|
reacord.createChannelMessage(channel, {}, <Uptime />)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -46,12 +45,28 @@ The instance can be rendered to multiple times, which will update the message ea
|
|||||||
const Hello = ({ subject }) => <>Hello, {subject}!</>
|
const Hello = ({ subject }) => <>Hello, {subject}!</>
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
const instance = reacord.send(channel)
|
const instance = reacord.createChannelMessage(channel)
|
||||||
instance.render(<Hello subject="World" />)
|
instance.render(<Hello subject="World" />)
|
||||||
instance.render(<Hello subject="Moon" />)
|
instance.render(<Hello subject="Moon" />)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Replying to Messages
|
||||||
|
|
||||||
|
Instead of sending messages to a channel, you may want to reply to a specific message instead. To do this, create an instance using `.createMessageReply()` instead:
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
const Hello = ({ username }) => <>Hello, {username}!</>
|
||||||
|
|
||||||
|
client.on("messageCreate", (message) => {
|
||||||
|
reacord.createMessageReply(
|
||||||
|
message,
|
||||||
|
{},
|
||||||
|
<Hello username={message.author.displayName} />,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Cleaning Up Instances
|
## Cleaning Up Instances
|
||||||
|
|
||||||
If you no longer want to use the instance, you can clean it up in a few ways:
|
If you no longer want to use the instance, you can clean it up in a few ways:
|
||||||
@@ -75,7 +90,7 @@ const reacord = new ReacordDiscordJs(client, {
|
|||||||
This section also applies to other kinds of application commands, such as context menu commands.
|
This section also applies to other kinds of application commands, such as context menu commands.
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
To reply to a command interaction, use the `.reply()` function. This function returns an instance that works the same way as the one from `.send()`. Here's an example:
|
To reply to a command interaction, use the `.createInteractionReply()` function. This function returns an instance that works the same way as the one from `.createChannelMessage()` and `.createMessageReply()`. Here's an example:
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
import { Client } from "discord.js"
|
import { Client } from "discord.js"
|
||||||
@@ -94,8 +109,8 @@ client.on("ready", () => {
|
|||||||
|
|
||||||
client.on("interactionCreate", (interaction) => {
|
client.on("interactionCreate", (interaction) => {
|
||||||
if (interaction.isCommand() && interaction.commandName === "ping") {
|
if (interaction.isCommand() && interaction.commandName === "ping") {
|
||||||
// Use the reply() function instead of send
|
// Use the createInteractionReply() function instead of createChannelMessage
|
||||||
reacord.reply(interaction, <>pong!</>)
|
reacord.createInteractionReply(interaction, {}, <>pong!</>)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -134,33 +149,55 @@ handleCommands(client, [
|
|||||||
name: "ping",
|
name: "ping",
|
||||||
description: "pong!",
|
description: "pong!",
|
||||||
run: (interaction) => {
|
run: (interaction) => {
|
||||||
reacord.reply(interaction, <>pong!</>)
|
reacord.createInteractionReply(interaction, {}, <>pong!</>)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "hi",
|
name: "hi",
|
||||||
description: "say hi",
|
description: "say hi",
|
||||||
run: (interaction) => {
|
run: (interaction) => {
|
||||||
reacord.reply(interaction, <>hi</>)
|
reacord.createInteractionReply(interaction, {}, <>hi</>)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ephemeral Command Replies
|
## Interaction Options
|
||||||
|
|
||||||
Ephemeral replies are replies that only appear for one user. To create them, use the `.ephemeralReply()` function.
|
Just like `.createChannelMessage()` and `.createMessageReply()`, interaction replies provide a way to specify certain `interaction.reply()` options.
|
||||||
|
|
||||||
```tsx
|
### Ephemeral Command Replies
|
||||||
|
|
||||||
|
Ephemeral replies are replies that only appear for one user. To create them, use the `.createInteractionReply()` function and provide `ephemeral` option.
|
||||||
|
|
||||||
|
```jsx
|
||||||
handleCommands(client, [
|
handleCommands(client, [
|
||||||
{
|
{
|
||||||
name: "pong",
|
name: "pong",
|
||||||
description: "pong, but in secret",
|
description: "pong, but in secret",
|
||||||
run: (interaction) => {
|
run: (interaction) => {
|
||||||
reacord.ephemeralReply(interaction, <>(pong)</>)
|
reacord.createInteractionReply(
|
||||||
|
interaction,
|
||||||
|
{ ephemeral: true },
|
||||||
|
<>(pong)</>,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
```
|
```
|
||||||
|
|
||||||
The `ephemeralReply` function also returns an instance, but ephemeral replies cannot be updated via `instance.render()`. You can `.deactivate()` them, but `.destroy()` will not delete the message; only the user can hide it from view.
|
### Text-to-Speech Command Replies
|
||||||
|
|
||||||
|
Additionally interaction replies may have `tts` option to turn on text-to-speech ability for the reply. To create such reply, use `.createInteractionReply()` function and provide `tts` option.
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
handleCommands(client, [
|
||||||
|
{
|
||||||
|
name: "pong",
|
||||||
|
description: "pong, but converted into audio",
|
||||||
|
run: (interaction) => {
|
||||||
|
reacord.createInteractionReply(interaction, { tts: true }, <>pong!</>)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
])
|
||||||
|
```
|
||||||
|
|||||||
@@ -24,7 +24,11 @@ function FancyMessage({ title, description }) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
reacord.send(channelId, <FancyMessage title="Hello" description="World" />)
|
reacord.createChannelMessage(
|
||||||
|
channel,
|
||||||
|
{},
|
||||||
|
<FancyMessage title="Hello" description="World" />,
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Reacord also comes with multiple embed components, for defining embeds on a piece-by-piece basis. This enables composition:
|
Reacord also comes with multiple embed components, for defining embeds on a piece-by-piece basis. This enables composition:
|
||||||
@@ -52,8 +56,9 @@ function FancyMessage({ children }) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
reacord.send(
|
reacord.createChannelMessage(
|
||||||
channelId,
|
channel,
|
||||||
|
{},
|
||||||
<FancyMessage>
|
<FancyMessage>
|
||||||
<FancyDetails title="Hello" description="World" />
|
<FancyDetails title="Hello" description="World" />
|
||||||
</FancyMessage>,
|
</FancyMessage>,
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ function TheButton() {
|
|||||||
const publicReply = event.reply(`${name} clicked the button. wow`)
|
const publicReply = event.reply(`${name} clicked the button. wow`)
|
||||||
setTimeout(() => publicReply.destroy(), 3000)
|
setTimeout(() => publicReply.destroy(), 3000)
|
||||||
|
|
||||||
const privateReply = event.ephemeralReply("good job, you clicked it")
|
const privateReply = event.reply("good job, you clicked it", {
|
||||||
|
ephemeral: true,
|
||||||
|
})
|
||||||
privateReply.deactivate() // we don't need to listen to updates on this
|
privateReply.deactivate() // we don't need to listen to updates on this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const instance = reacord.send(
|
|||||||
|
|
||||||
For a multi-select, use the `multiple` prop, then you can use `values` and `onChangeMultiple` to handle multiple values.
|
For a multi-select, use the `multiple` prop, then you can use `values` and `onChangeMultiple` to handle multiple values.
|
||||||
|
|
||||||
```tsx
|
```jsx
|
||||||
export function FruitSelect({ onConfirm }) {
|
export function FruitSelect({ onConfirm }) {
|
||||||
const [values, setValues] = useState([])
|
const [values, setValues] = useState([])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user