discord
Discord is a voice, video and text communication service to talk and hang out with your friends and communities.
Usage
import { discord } from 'netzo/apis/discord.ts'
const api = discord({
tokenType: Deno.env.get('DISCORD_TOKEN_TYPE') ?? 'Bot',
token: Deno.env.get('DISCORD_TOKEN')
})
Configuration
The discord
factory function expects an object with the following, and returns an object with an API client api
.
Param | Type | Default | Description |
---|---|---|---|
tokenType | string | Deno.env.get("DISCORD_TOKEN_TYPE") ?? "Bot" | the token type |
token | string | token: Deno.env.get("DISCORD_TOKEN") | the token to use for authentication |
Refer to the API documentation to get the required information.
Examples
The following examples assume you have created an api client instance.
Get channel
Get a channel by id.
const resultData = await api.channels[CHANNEL_ID].get<Channel>()
Find messages
Find all messages on a specific channel.
const query: QueryMessages = {}
const resultData = await api.channels[CHANNEL_ID].messages.get<Message[]>(query)
Add message
Post a message to a channel.
const data: DataAddOrUpdateMessage = { content: 'New message' }
const resultData = await api.channels[CHANNEL_ID].messages.post<Message>(data)
Update Message
Update a message by id.
const data: DataAddOrUpdateMessage = { content: 'Updated message' }
const resultData = await api.channels[CHANNEL_ID].messages[MESSAGE_ID].patch<Message>(data)