Typescript Bot

Você também pode gostar

Fazer download em txt, pdf ou txt
Fazer download em txt, pdf ou txt
Você está na página 1de 3

DEFINE COMO O BOT ESTÁ PENSANDO, usar deferReply + editReply

await interaction.deferReply({
ephemeral: true,
})

setTimeout(() => {
interaction.editReply({
content: "Ficar sem botão, testando funções!"
})
}, 3500)

-----------------------------------------------------------------------------------
----------------------------
DEFININDO BOTÃO E SUA FUNÇÃO EM NEW COLLECTION

import { ActionRowBuilder, ApplicationCommandType, ButtonBuilder, ButtonStyle,


Collection } from "discord.js";
import { Command } from "../../structs/types/Command";

export default new Command({


name: "botao",
description: "teste de botões em ts",
type: ApplicationCommandType.ChatInput,
run({interaction}){
const row = new ActionRowBuilder<ButtonBuilder>({components: [
new ButtonBuilder({custom_id: "test-button", label: "Clique Aqui!",
style: ButtonStyle.Success })
]})

interaction.reply({ephemeral: true, content: "Ficar sem botão, testando


funções!", components: [row]})

},
buttons: new Collection([
["test-button", async (interaction) => {
interaction.update({components: []})
}]
])
})

-----------------------------------------------------------------------------------
-----------------------------
INTERAÇÕES DE COMANDOS DE BARRA

.update (dá um opdate nos components e na mensagem


.reply (responde o usuario)
.followup (responde a resposta ao usuario)
.deleteReply (apaga a mensagem enviada na interação)
.setTimeout (() => {}, milissegundos) (define um tempo até acontecer a ação)
.deferReply ({ ephemeral = true }) (adia o tempo de resposta, bot fica pensando)

-----------------------------------------------------------------------------------
-------------------
OPÇÕES DE COMANDOS

OPÇÃO NO SLASH COMMAND, TIPO UM PLACEHOLDER COLHENDO ALGO ESPECICO, COMO USUARIO,
CARGO, NÚMERO E ETC.

options: [
{
name: "texto", (LABEL)
description: "Digite um texto!", (PLACE HOLDER)
type: ApplicationCommandOptionType.String, (TIPO)
required: true, (SE VAI SER OBRIGATÓRIO OU NÃO)

DEFINE DENTRO DA FUNÇÃO ASSINCRONA, CRIA UM VARIAVEL PARA ELA COM CONST (NOME, true
caso seja obrigatório) - assim vai retornar só string
APÓS CRIAR A CONST EU REPLICO A MENSAGEM PELO BOT

async run({interaction, options}){

const text = options.getString("texto", true)

await interaction.reply({
content: `${text}`});

SE EU DEFINIR PARA NÃO SER OBRIGTÓRIO O PLACE ROLDER

async run({interaction, options}){

const text = options.getString("texto")

if (text){
await interaction.reply({ content: `Você disse ${text}`})
} else {
await interaction.reply('Você não disse nada')
}

setTimeout(() => {
interaction.deleteReply()
}, 2000)
},

})

EU FAÇO UMA VERIFCAÇÃO IF SE TEM TEXTO, SE NÃO TIVER ELE RETORNAR UM TEXTO PRE
DEFINIDO, SE TIVER O PLACEHOLDER ELE REPLICA O IF

============================
SUB COMMANDO
options: [
{
name: "texto"
description: "Digite um texto!"
type: ApplicationCommandOptionType.SubCommand, (TIPO)
}

===========================
CRIANDO INTERAÇÃO EM APPS

import { ActionRowBuilder, ApplicationCommandOptionType, ApplicationCommandType,


ButtonBuilder, ButtonStyle, Collection, Options } from "discord.js";
import { Command } from "../../structs/types/Command";

export default new Command({

name: "mencionar",
type: ApplicationCommandType.User,
async run({interaction, options}){
if (!interaction.isUserContextMenuCommand()) return;

const mention = interaction.targetMember;


interaction.reply({
content: `${mention}`,
})
}
})

Você também pode gostar