Discord-buttons Action Row dont show up - javascript

I'm making a discord bot with discord.js. I want to add buttons to embed messages send by bot. but my buttons don't show up and i don't see any errors in the console.
Here's my code:
const { MessageButton, MessageActionRow } = require("discord-buttons");
module.exports = {
name: "yardım",
description: "Yardım Al",
async execute(client, message, args, Discord) {
const embed = new Discord.MessageEmbed()
.setAuthor(message.guild.me.user.username, message.guild.me.user.displayAvatarURL())
.setColor(message.guild.me.displayHexColor)
.setDescription("{Turtle}'ı nasıl kullanacağını bilmiyor musun? Çok Yazık! Neyse bu dert değil. \n\n 'Bilmemek değil, öğrenmemek ayıp!' derler. Hadi Öğrenelim! \n \u200B")
.addFields(
{ name: 'Komutlar', value: 'Bütün komutlara [buradan](https://www.youtube.com/watch?v=dQw4w9WgXcQ) ulaşabilirsin. \n\u200B' },
{ name: 'Yardım', value: 'Merak ettiklerinizi ve anlamadığımız şeyleri [buradan](https://www.youtube.com/watch?v=dQw4w9WgXcQ) botun geliştiricisine sorabilirsin. \n\u200B' },
{ name: 'Destek Olun', value: 'Bu projeyi daha da ileri götürmek için sizin desteğinize ihtiyacım var. [Buradan](https://www.youtube.com/watch?v=dQw4w9WgXcQ) nasıl destek olabileceğinize bakabilirsiniz.' },
)
const embedLinks = new MessageActionRow().addComponents(
new MessageButton()
.setStyle("url")
.setURL('https://www.youtube.com/watch?v=nYh-n7EOtMA')
.setLabel('URL 2')
.setID("url2"),
new MessageButton()
.setStyle('url')
.setURL('https://www.youtube.com/watch?v=nYh-n7EOtMA')
.setLabel('URL')
.setID("url2")
)
console.log(embedLinks);
message.channel.send({
embed: embed,
component: embedLinks
});
}
}
Output on discord channel:

Solution was easy.
go to your master file like 'main.js' or 'index.js'.
put this require('discord-buttons')(client); after importing discord js

Related

How to schedule a bot message in Discord.js v14 (Slash commands)?

I need to schedule some messages for users and I would like to do this with the bot. If possible choosing the date and time of the message.
I'm very new to this part so I'm asking for help.
In my code, I add a .js file for the command inside the commands folder.
By default, commands start with:
const Discord = require("discord.js")
module.exports = {
name: "schedule", // Coloque o nome do comando
description: "Schedule messages.", // Coloque a descrição do comando
type: Discord.ApplicationCommandType.ChatInput,
options: [
{
name: "schedule",
description: "Schedule messages.",
type: Discord.ApplicationCommandOptionType.String,
required: true,
}
],
run: async (client, interaction) => {
You can use setTimeout() for making shedules
setTimeout(() => {
console.log("Shedule is running");
//Do whatever you wanted to do when the time comes
//...
}, 3000)//3000 = 3 seconds

verify button discord.js v14

I am trying to create a verify button but i cant get it to work, im very new to discord.js so the code is very messy. i am using discord.js v14 btw
I want the verify button to give the person who clicks it the #verified role (1009826361248055438) and to send a message afterwards so they see they have been verified.
const {
EmbedBuilder,
ApplicationCommandType,
ActionRowBuilder,
ButtonBuilder,
Message,
Emoji,
InviteTargetType,
} = require("discord.js");
module.exports = {
name: "sendverify",
description: "send the verify",
cooldown: 3000,
type: ApplicationCommandType.ChatInput,
default_member_permissions: "ManageRoles", // permission required
options: [
{
name: "channel",
description: "the channel to send it to.",
type: 7,
required: true,
},
],
run: async (client, interaction) => {
/** Get the buttons
* #param {Boolean} toggle
* #param {string}[choice = null] choice
*/
const getButtons = (toggle = false, choice) => {
const row3 = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel("Verify")
.setCustomId("verify")
.setStyle(
toggle == true && choice == "green" ? "Secondary" : "Success"
)
.setDisabled(toggle)
.setEmoji("1009822176830034010")
);
return row3;
};
const channel = interaction.options.get("channel").channel;
const embed1 = new EmbedBuilder()
.setTitle("Accepting the rules")
.setDescription(
"**Please read the rules before clicking the verify button!**"
)
.setColor(0x39f077)
.setFooter({
text: "By clicking verify you have agreed to the rules, and face the consequences if you don't follow them.",
});
return (
channel.send({ embeds: [embed1], components: [getButtons()] }),
interaction.reply({ content: "msg sent.", ephemeral: true })
);
},
};

DiscordAPIError: Cannot send an empty message with and embed

I can't figure out the issue, it always comes up with cannot send an empty message
module.exports = {
name: 'actualhelp',
description: "here is some ACTUAL help",
execute(message, args, Discord){
const newEmbed = new Discord.MessageEmbed()
.setColor('#304281')
.setTitle('Help')
.setURL('URL')
.setDescription('Here is some basic help')
.addFields(
{name: '4/102', value: 'Base Set Charizard'},
{name: 'cool', value: 'You will become cool with the Looking Epic role'},
{name: 'ugly', value: 'Thats not nice, you are now not cool and have your Looking Epic role removed if you already had it'},
{name: 'help', value: 'get fooled kiddo, I aint helping you'},
{name: 'kick', value: 'checks to see if you can kick people'},
{name: 'ping', value: 'play some ping pong with me'}
)
.setImage('Image url');
message.channel.send({newEmbed});
}
}
The way you are sending the embed currently is identical to this:
message.channel.send({newEmbed: newEmbed})
However this is not a valid property to set. Instead, you can do embed: newEmbed
message.channel.send({
embed: newEmbed
})
or on v13, embeds: [newEmbed]
message.channel.send({
embeds: [newEmbed]
})

(Discord.JS) How do I listen for a user mention for a specific user chosen by the author

So I am in the process of making a Discord.Js bot that includes a command that will let me provide information on certain users. For example: I want to add a command that will provide the PlayStation gamer tag of a mentioned user (lets say the specific users id is <#123>). The input message would look something like this :
"!psn #mention" then the bot would output his gamertag which I will manually log as--> message.channel.send('Here is <#1235467890> 's #psnname');
I want to include the gamertag every member in my server so anyone can request it upon mentioning it with the command "psn", I have gone through tons of trial and error with different code but i can not figure out how to specify the message.mention.members.first(); by a specific user id. Please help
module.exports = {
name: 'codtag',
execute(message, args){
let member = message.mentions.members.first();
if(!args.length){
return message.channel.send({embed: {
color: '#da1801',
title: 'Activision Gamertag: Error',
description: 'You need to tag a user dummy.'
}})
}
if (member !== '<#772597378142306354>')return;
else if (member === `772597378142306354`)return
{
(args[0] === member)
return message.channel.send({embed: {
color: '#1243c6',
title: 'Activision Gamertag',
description: 'Here is <#772597378142306354> Activision: \n\n **WalterWhite#2396124**'
}});
}}
}
For anyone that finds this post with the same question, I figured it out. The following code works perfectly
I added:
let guild = message.mentions.members.first();
I also included the condition for args[0] as:
if (message.mentions.members.had('put users id here without the <#>')
module.exports = {
name: 'cod',
execute(message, args){
let guild = message.mentions.members.first();
if(!args.length){
return message.channel.send({embed: {
color: '#da1801',
title: 'Activision Gamertag: Error',
description: 'You need to tag a valid user dummy.'
}})
}
if(message.mentions.members.has('772597378142306354')){
(args[0] == guild)
message.channel.send({embed: {
color: '#1243c6',
title: 'Activision Gamertag',
description: 'Here is <#772597378142306354> Activision: \n\n **WalterWhite#2396124**',
footer: {
text: 'Message #issmayo if your gamertag is not included.'
}
}});
}

How to create an embed for statistical information provided by my Discord bot (Covid Statistics)

I've created a Discord bot that will give me Covid statistics on any country on command, however it's only displayed to me in raw text, I've seen images of embeds like this:
I'm interested to have my data displayed like this in my bots reply, this is the code I am using for it:
const axios = require('axios');
const countries = require("./countries.json");
const url = 'https://api.covid19api.com/total/country/';
const WAKE_COMMAND = 'cases';
client.on('message', async (msg) => {
const content = msg.content.split(/[ ,]+/);
if(content[0] === WAKE_COMMAND){
if(content.length > 2){
msg.reply("Too many arguments...")
}
else if(content.length === 1){
msg.reply("Not enough arguments")
}
else if(!countries[content[1]]){
msg.reply("Wrong country format")
}
else{
const slug = content[1]
const payload = await axios.get(`${url}${slug}`)
const covidData = payload.data.pop();
msg.reply(`Confirmed: ${covidData.Confirmed}, Deaths: ${covidData.Deaths}, Recovered: ${covidData.Recovered}, Active: ${covidData.Active} `)
}
}
});
Any help on how I should rearrange my code to look more like the embed above would be much appreciated.
Thanks!
You can do this using the MessageEmbed class.
Here an example of it being used:
const embed = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle("A title")
.setDescription("A description")
.setTimestamp()
message.channel.send(embed);
// You can also use the code below, in your case
msg.reply(embed);
You can find more examples of this here
If you want to create something like ProDyno has, you'll want to use the .addLine method on the MessageEmbed class, this will allow you to toggle things like inline to be true so you can put stats next to each other. For example:
.addFields(
{ name: 'Inline title', value: 'Inline text', inline: true },
{ name: 'Inline title', value: 'Inline text', inline: true },
)

Categories