-
-
Save pedroricardo/da90fd467962ca8424cfc56dc3a54df6 to your computer and use it in GitHub Desktop.
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" | |
} |
pessoal quando eu executo o comando node .
ele da um erro fica assim:
Error: Cannot find module 'C:\Users\Desktop\bot_legal\index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:303:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
at resolveMainPath (internal/modules/run_main.js:12:25)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:66:24)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
path: 'C:\Users\\Desktop\bot_legal\package.json',
requestPath: 'C:\Users\\Desktop\bot_legal'
}
algm tem o comando de ban? plsss
Boa Noite, Bom Dia, Boa Tarde, Esse é o Código de Ban.
`// Import the discord.js module
const Discord = require('discord.js');
// Create an instance of a Discord client
const client = new Discord.Client();
/**
- The ready event is vital, it means that only after this will your bot start reacting to information
- received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// Ignore messages that aren't from a guild
if (!message.guild) return;
// if the message content starts with "!ban"
if (message.content.startsWith('!ban')) {
// Assuming we mention someone in the message, this will return the user
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
const user = message.mentions.users.first();
// If we have a user mentioned
if (user) {
// Now we get the member from the user
const member = message.guild.member(user);
// If the member is in the guild
if (member) {
/**
* Ban the member
* Make sure you run this on a member, not a user!
* There are big differences between a user and a member
* Read more about what ban options there are over at
* https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
*/
member
.ban({
reason: 'They were bad!',
})
.then(() => {
// We let the message author know we were able to ban the person
message.reply(Successfully banned ${user.tag}
);
})
.catch(err => {
// An error happened
// This is generally due to the bot not being able to ban the member,
// either due to missing permissions or role hierarchy
message.reply('I was unable to ban the member');
// Log the error
console.error(err);
});
} else {
// The mentioned user isn't in this guild
message.reply("That user isn't in this guild!");
}
} else {
// Otherwise, if no user was mentioned
message.reply("You didn't mention the user to ban!");
}
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');`
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
Tente Trocar Seu Código Para
const m = await message.channel.send('ping?'); // Enviando a Mensagem
m.edit(`🏓 **| Pong!**\nLatência do Server: **${m.createdTimestamp -
message.createdTimestamp}ms.**\nLatência da API: **${Math.round(
client.ws.ping
)}ms**` // Editando e Enviando o Ping, O Ping Fica Melhor Quanto Mais Baixo.
);
};
// Vai Funcionar
Oi, eu tenho um code handler, e tenho um autorole, tenho 39 commands ao total, mas tudo dando certo, pedi até umas informações e tal, e minha handler está tão ruim porque, pega todos commands mas o autorole não pega, e eu tinha feito em um tutorial de yt e tal.., e até que pegou bem, porém o problema é quando eu executo o autorole, ele fala que
buscas.run is not a function
client.on('message',message => { if (message.author.bot) return; if (message.channel.type == 'dm') return; if (!message.content.toLowerCase().startsWith(config.prefix)) return; if (message.content.startsWith(
<@!${client.user.id}>) || message.content.startsWith(
<@${client.user.id}>`)) return;
const args = message.content
.trim().slice(config.prefix.length)
.split(/ +/g);
const file = args.shift().toLowerCase();
try {
var buscas = require(`../tt/commands/${file}.js`)
console.log(buscas)
buscas.run(client, message, args);
} catch (err) {
console.error('Erro:' + err);
``}
});
esse é meu handler, só queria saber o porque do error, e não tem nada errado no autorole, tanto é que meu amigo refez ela pra mim em um video yt, e mesmo assim.., a autorole pega e a minha não pega.
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
);
}
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 {
estou com o mesmo problema! Ja conseguiu resolver?
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.
Mesmo problema alguem conseguiu resolver?
ol
O meu bot não reconhece o prefixo o que há de errado?
