Skip to content

Instantly share code, notes, and snippets.

@pedroricardo
Last active January 18, 2024 11:09
Show Gist options
  • Save pedroricardo/da90fd467962ca8424cfc56dc3a54df6 to your computer and use it in GitHub Desktop.
Save pedroricardo/da90fd467962ca8424cfc56dc3a54df6 to your computer and use it in GitHub Desktop.
Como Criar Bot para Discord em Javascript #2 https://www.youtube.com/watch?v=KYnXhtyqQRQ
const Discord = require("discord.js"); //baixar a lib
const client = new Discord.Client();
const config = require("./config.json");
client.on("ready", () => {
console.log(`Bot foi iniciado, com ${client.users.size} usuários, em ${client.channels.size} canais, em ${client.guilds.size} servidores.`);
client.user.setPresence({ game: { name: 'comando', type: 1, url: 'https://www.twitch.tv/pedroricardo'} });
//0 = Jogando
// 1 = Transmitindo
// 2 = Ouvindo
// 3 = Assistindo
});
client.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
if(!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const comando = args.shift().toLowerCase();
// coamdno ping
if(comando === "ping") {
const m = await message.channel.send("Ping?");
m.edit(`Pong! A Latência é ${m.createdTimestamp - message.createdTimestamp}ms. A Latencia da API é ${Math.round(client.ping)}ms`);
}
});
client.login(config.token);
{
"prefix": "!",
"token": "XXXXXXX"
}
@zzzjss
Copy link

zzzjss commented May 13, 2021

O meu aparece isto: Pong! A latência é ${m.createdTimestamp - message.createdTimestamp}ms. A latência da API é ${Math.round(client.ping)}ms Print: https://prnt.sc/pfqse1

if(comando === "ping") {
const m = message.channel.send("Ping?");
m.edit(Pong! A latencia eh ${m.createdTimestamp - message.createdTimestamp}ms. A Latencia da API eh ${Math.round(client.ws.ping)}ms);
}

@ryanfigueredo
Copy link

Ao iniciar o bot, com node . aparece esse erro.

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\ryanf\Desktop\Bot.js\node_modules\discord.js\src\client\Client.js:544:13)
at new Client (C:\Users\ryanf\Desktop\Bot.js\node_modules\discord.js\src\client\Client.js:73:10)
at Object. (C:\Users\ryanf\Desktop\Bot.js\bot.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {

@VilelinhaJunior
Copy link

estou com o mesmo problema! Ja conseguiu resolver?

@BrunoFreschi
Copy link

Olá deve estar faltando alguma instrução nas classe que são chamadas. Pelo oque consegui entender não esta encontrando alguns módulos.
Vou dar uma pesquisada caso encontrem mandem postem aqui.

@VitorJoseDeAssis
Copy link

VitorJoseDeAssis commented Jan 31, 2022

Quando tento iniciar o bot aparece esse erro, não estou entendendo o pq
unknown

@bMexe
Copy link

bMexe commented Feb 4, 2022

Mesmo problema alguem conseguiu resolver?

@VitorJoseDeAssis
Copy link

VitorJoseDeAssis commented Feb 4, 2022 via email

@Davizinsouza
Copy link

ol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment