so, i have learn how to make a discord bot from a youtube channel which called "CodeLyon" and there is the error:enter image description here
do someone know how to fix it? (I searched a long time for solving this problem and i didnt find anything)
If you are using Discord JS V12 it's:
const discord = require("discord.js");
const Embed = new discord.MessageEmbed();;
Otherwise, it is:
const discord = require("discord.js");
const Embed = new discord.RichEmbed();;
Related
so i was trying to implement a database for my discord bot but when it try to call on it all i get is
UnhandledPromiseRejectionWarning: Error: Cannot find module '../database/db'
heres the bit thats failing
const Discord = require('discord.js');
const bot = new Discord.Client();
const fs = require('fs');
const util = require('util');
const mysql = require('mysql2');
let connection;
require('dotenv').config();
///Token for discord bot
(async () => {
connection = await require('../database/db');
await bot.login(process.env.BOT_TOKEN);
})();
and heres my file structure
i tried installing mysql2 globally to see if that work help and it didnt :(
EDIT:
someone asked what the file inside database looked like
Because you didnt give us enough info i cant really help but if your file name your trying to get is db and your file name is index.js then this should work
connection = await require('./database/db');
NOTE : if this doesnt work please add more screenshots / more info about your file locations
I am trying to get my Discord bot to react to people's messages. For example, if somebody said "welcome", the bot will react to their message, because it has the word welcome, which I would set the keyword too. I understand how to get the bot to reply to messages with a response, but not reactions.
In discord.js you can use something like this:
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("message", message => {
if(message.content === "welcome") {
message.react("😄");
}
}
client.login("YOUR_TOKEN");
This in the Discord.js Docs might be helpful as well.
I'm making a discord bot but when I do my help command nothing happens.
The code for my help command is:
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
const Embed = new Discord.RichEmbed()
.setColor("YELLOW")
.setTitle("HardBot - Help")
.setDescription(":tada: Subscribe to our YouTube channel!")
.addField("meme", "youtube",true)
.addField("servers", "ping",true)
.addField("invite",true)
.addField("our prefix is h!",true);
message.channel.send(Embed)
}
module.exports.help = {
name: "help"
}
Make sure to update discord.js by using npm i discord.js#latest in your terminal. Then replace RichEmbed with MessageEmbed.
For all changes in discord.js v12 click here.
Edit:
Make sure you fill every field from an embed with values otherwise it is an invalid form body.
I've been coding a Discord bot using js for a couple days now and most everything has been working fine. I am trying to get my bot to respond to a code word but the command isn't working unless I use my prefix which is !.
I've tried pretty much every variation of the code, but none is working.
Example of the command:
if(message.content.includes('ping')) {
message.reply('Pong');
}
if your code looks like
const Discord = require('discord.js');
const client = new Discord.Client();
let token = "your token here";
client.on('message', message => {
if(message.content.includes('ping')) {
message.reply('Pong');
}
});
client.login(token)
and nothing happens when you send 'ping', then it looks like some technical issue. Otherwise, you have to send the whole code so people can take a look and tell you what is wrong.
I have a question demanding DiscordJS.
It is, how to properly delete a Discord message that the bot sent?
I know it's a newbie question, but I'm new to DiscordJS.
I'm very thankful for all the responses I get, no matter if helpful or not.
You have to use the .delete method for the message object in order to delete the message. Just wait until the message is sent and then delete it after a certain period of time.
For (Rich)embeds, use the following code:
const Discord = require('discord.js');
const RichEmbed = new Discord.RichEmbed()
.setAuthor('test');
const message = await message.channel.send({ embed: RichEmbed }).then(r => r.delete('time in milliseconds'));
For normal messages, use the following code:
const message = await message.channel.send('Hello').then(r => r.delete('time in milliseconds'))