update readme & remove useless comments
This commit is contained in:
56
README.md
56
README.md
@@ -22,23 +22,51 @@ pnpm add reacord react discord.js
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
<!-- prettier-ignore -->
|
|
||||||
```tsx
|
```tsx
|
||||||
import * as React from "react"
|
import { useState } from "react"
|
||||||
import { Embed, Button } from "reacord"
|
import { Embed, EmbedField, Button } from "reacord"
|
||||||
|
|
||||||
|
interface EmbedCounterProps {
|
||||||
|
count: number
|
||||||
|
visible: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function EmbedCounter({ count, visible }: EmbedCounterProps) {
|
||||||
|
if (!visible) return <></>
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Embed title="the counter">
|
||||||
|
<EmbedField name="is it even?">{count % 2 ? "no" : "yes"}</EmbedField>
|
||||||
|
</Embed>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function Counter() {
|
function Counter() {
|
||||||
const [count, setCount] = React.useState(0)
|
const [showEmbed, setShowEmbed] = useState<boolean>(false)
|
||||||
return (
|
const [count, setCount] = useState<number>(0)
|
||||||
<>
|
const instance = useInstance()
|
||||||
<Embed title="Counter">
|
|
||||||
This button has been clicked {count} times.
|
return (
|
||||||
</Embed>
|
<>
|
||||||
<Button onClick={() => setCount(count + 1)}>
|
this button was clicked {count} times
|
||||||
+1
|
<EmbedCounter count={count} visible={showEmbed} />
|
||||||
</Button>
|
<Button
|
||||||
</>
|
style="primary"
|
||||||
)
|
label="clicc"
|
||||||
|
onClick={() => setCount(count + 1)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="secondary"
|
||||||
|
label={showEmbed ? "hide embed" : "show embed"}
|
||||||
|
onClick={() => setShowEmbed(!showEmbed)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="danger"
|
||||||
|
label="deactivate"
|
||||||
|
onClick={() => instance.destroy()}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { raise } from "@reacord/helpers/raise.js"
|
import { raise } from "@reacord/helpers/raise.js"
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
Embed,
|
||||||
|
EmbedField,
|
||||||
Link,
|
Link,
|
||||||
Option,
|
Option,
|
||||||
ReacordDiscordJs,
|
ReacordDiscordJs,
|
||||||
@@ -11,7 +13,6 @@ import type { TextChannel } from "discord.js"
|
|||||||
import { ChannelType, Client, IntentsBitField } from "discord.js"
|
import { ChannelType, Client, IntentsBitField } from "discord.js"
|
||||||
import "dotenv/config"
|
import "dotenv/config"
|
||||||
import { kebabCase } from "lodash-es"
|
import { kebabCase } from "lodash-es"
|
||||||
import * as React from "react"
|
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
|
|
||||||
const client = new Client({ intents: IntentsBitField.Flags.Guilds })
|
const client = new Client({ intents: IntentsBitField.Flags.Guilds })
|
||||||
@@ -53,9 +54,57 @@ await createTest("basic", (channel) => {
|
|||||||
reacord.createChannelMessage(channel).render("Hello, world!")
|
reacord.createChannelMessage(channel).render("Hello, world!")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await createTest("readme counter", (channel) => {
|
||||||
|
interface EmbedCounterProps {
|
||||||
|
count: number
|
||||||
|
visible: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function EmbedCounter({ count, visible }: EmbedCounterProps) {
|
||||||
|
if (!visible) return <></>
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Embed title="the counter">
|
||||||
|
<EmbedField name="is it even?">{count % 2 ? "no" : "yes"}</EmbedField>
|
||||||
|
</Embed>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Counter() {
|
||||||
|
const [showEmbed, setShowEmbed] = useState(false)
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
const instance = useInstance()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
this button was clicked {count} times
|
||||||
|
<EmbedCounter count={count} visible={showEmbed} />
|
||||||
|
<Button
|
||||||
|
style="primary"
|
||||||
|
label="clicc"
|
||||||
|
onClick={() => setCount(count + 1)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="secondary"
|
||||||
|
label={showEmbed ? "hide embed" : "show embed"}
|
||||||
|
onClick={() => setShowEmbed(!showEmbed)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style="danger"
|
||||||
|
label="deactivate"
|
||||||
|
onClick={() => instance.destroy()}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
reacord.createChannelMessage(channel).render(<Counter />)
|
||||||
|
})
|
||||||
|
|
||||||
await createTest("counter", (channel) => {
|
await createTest("counter", (channel) => {
|
||||||
const Counter = () => {
|
function Counter() {
|
||||||
const [count, setCount] = React.useState(0)
|
const [count, setCount] = useState(0)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
count: {count}
|
count: {count}
|
||||||
|
|||||||
@@ -141,14 +141,12 @@ interface Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleCommands(client: Client, commands: Command[]) {
|
function handleCommands(client: Client, commands: Command[]) {
|
||||||
// Registering commands when client is ready
|
|
||||||
client.once(Events.ClientReady, () => {
|
client.once(Events.ClientReady, () => {
|
||||||
for (const { name, description } of commands) {
|
for (const { name, description } of commands) {
|
||||||
client.application?.commands.create({ name, description })
|
client.application?.commands.create({ name, description })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Subscribing to interactionCreate event
|
|
||||||
client.on(Events.InteractionCreate, (interaction) => {
|
client.on(Events.InteractionCreate, (interaction) => {
|
||||||
if (interaction.isCommand()) {
|
if (interaction.isCommand()) {
|
||||||
for (const command of commands) {
|
for (const command of commands) {
|
||||||
|
|||||||
Reference in New Issue
Block a user