The error:
CombinedError (2)
Received one or more errors
1 ValidationError > s.nullish
| Expected undefined or null
|
| Received:
| | [Function: displayAvatarURL]
2 ValidationError > s.string
| Expected a string primitive
|
| Received:
| | [Function: displayAvatarURL]
I've looked back on my code but everything looks good so far. This is only in my embed.js file and no where else.
The code:
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("embed")
.setDescription('Return an embed.'),
async execute(interaction, client) {
const embed = new EmbedBuilder()
.setTitle(`This is an EMBED`)
.setDescription('This is a EMBED description')
.setColor(0xFA03CA)
.setImage(client.user.displayAvatarURL())
.setThumbnail(client.user.displayAvatarURL())
.setTimestamp(Date.now())
.setAuthor({
url: `https://www.twitch.tv/x333en`,
iconURL: interaction.user.displayAvatarURL(),
name: interaction.user.tag
})
.setFooter({
iconURL: client.user.displayAvatarURL(),
text: client.user.tag
})
.setURL(`https://discord.gg/8YtDhpbCJf`)
.addFields([
{
name: `Field 1`,
value: `Field Value 1`,
inline: true
},
{
name: `Field 2`,
value: `Field value 2`,
inline: true
}
]);
await interaction.reply({
embeds: [embed]
})
}
This is my code as of right now.
I've tried to move stuff around but it seem to cause more issues so i just left it be.
Related
I was wondering if it was possible to make it so that you can have the bot search for more than one server when putting in the command.
for example !mc server.com
bot: server.com
playercount: ?/?
other info
onst { Client, Intents, Message} = require('discord.js');
const util = require('minecraft-server-util');
const {EmbedBuilder} = require('discord.js');
const options = {
timeout: 1000 * 5,
enableSRV: true
};
const prefix = "!mcstatus";
const client = new Client({
intents: [
"Guilds",
"GuildMessages",
"MessageContent"
]
});
client.on('ready', () => {
console.log('bot started');
client.user.setPresence({ activities: [{ name: `${server_ip}`, type: 'WATCHING' }], status: 'active' });
});
const server_ip = "mc.hypixel.net";
const server_port = 25565;
client.on('messageCreate', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if(message.content.startsWith(prefix)){
util.status(server_ip, server_port, options)
.then((result) => {
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("mcdonalds")
.setDescription(`This will show the status and info about the minecraft server \n **Server ip:** ${server_ip} \n **Server port:** ${server_port}`)
.addFields(
{name:"Server Version", value: `${result.version.name}`},
{name:"Server Protocol Version", value:`${result.version.protocol}`},
{name:"Players Online", value:`${result.players.online}`},
{name:"Max Players", value:`${result.players.max}`},
{name:"MOTD (May Not Display Accurately)", value:`${result.motd.clean}`},
{name:"Latency", value:`${result.roundTripLatency}`},
)
.setTimestamp()
message.channel.send({embeds: [embed]})
})
.catch((error) => {
console.log(error);
const embed = new EmbedBuilder()
.setColor("#808080")
.setTitle("mcdonalds")
.setDescription(`The server was unable to be pinged or you mis-typed the info`)
.setTimestamp()
message.channel.send({embeds: [embed]})
})}});
client.login("okent");
if there is a way this would be very cool
You can use the String.prototype.split() method to turn your string into an array of strings, for example:
let args = message.content.split(" "); // Splitting with a blank space.
args = args.slice(1); // Remove the first argument which would be the command itself.
const server_port = 25565; // Leave the default port for MC servers.
if (args.length < 1) return message.reply("Didn't provide arguments.")
// Run a forEach loop for every argument.
args.forEach((arg) => {
util
.status(arg, server_port, options)
.then((result) => {
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("Results")
.setDescription(
`This will show the status and info about the minecraft server \n **Server ip:** ${arg} \n **Server port:** ${server_port}`
)
.addFields(
{ name: "Server Version", value: `${result.version.name}` },
{
name: "Server Protocol Version",
value: `${result.version.protocol}`,
},
{ name: "Players Online", value: `${result.players.online}` },
{ name: "Max Players", value: `${result.players.max}` },
{
name: "MOTD (May Not Display Accurately)",
value: `${result.motd.clean}`,
},
{ name: "Latency", value: `${result.roundTripLatency}` }
)
.setTimestamp();
message.channel.send({ embeds: [embed] });
})
.catch((error) => {
const embed = new EmbedBuilder()
.setColor("#808080")
.setTitle("Error")
.setDescription(
`${arg} was unable to be pinged or you mis-typed the info`
)
.setTimestamp();
message.channel.send({ embeds: [embed] });
});
});
(Make sure to review the code before pasting it in)
The snippet above simply splits the message.content string into an array of strings then runs a loop for each string in the array which runs the util status check and then returns a new embed, or an error.
Make sure to mark this as the answer if it helped.
I am making a ticket system, everything works fine except when I go onto a different account to test out what the ticket system looks like for the people using it, I try to react to the "Player Report", "Bug Report", etc... as seen in the code, it just says i am unable to use the buttons and then throws this error.
Full error:
C:\Users\wrigh\Documents\Discord Bots\Practice Bot - Copy\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:90
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
^
Error [INTERACTION_ALREADY_REPLIED]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.reply (C:\Users\wrigh\Documents\Discord Bots\Practice Bot - Copy\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:90:46)
at C:\Users\wrigh\Documents\Discord Bots\Practice Bot - Copy\Events\Ticket\initialTicket.js:86:24
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async C:\Users\wrigh\Documents\Discord Bots\Practice Bot - Copy\Events\Ticket\initialTicket.js:79:9
at async Object.execute (C:\Users\wrigh\Documents\Discord Bots\Practice Bot - Copy\Events\Ticket\initialTicket.js:20:9) {
[Symbol(code)]: 'INTERACTION_ALREADY_REPLIED'
Ticket.js Code:
const { MessageEmbed, CommandInteraction, MessageActionRow, MessageButton } = require("discord.js");
const { OPENTICKET } = require("../../Structures/config.json");
module.exports = {
name: "ticket",
description: "Setup your ticket",
permission: "ADMINISTRATOR",
/**
*
* #param {CommandInteraction} interaction
*/
async execute(interaction) {
const { guild } = interaction;
const Embed = new MessageEmbed()
.setAuthor(
guild.name + " | Ticketing System",
guild.iconURL({ dynamic: true})
)
.setDescription(
"Open a ticket to discuss any of the issues listed on the button."
)
.setColor("BLUE");
const Buttons = new MessageActionRow();
Buttons.addComponents(
new MessageButton()
.setCustomId("player")
.setLabel("Player Report")
.setStyle("PRIMARY")
.setEmoji("🏮"),
new MessageButton()
.setCustomId("bug")
.setLabel("Bug Report")
.setStyle("SECONDARY")
.setEmoji("✔"),
new MessageButton()
.setCustomId("other")
.setLabel("Other Report")
.setStyle("SUCCESS")
.setEmoji("❤"),
);
await guild.channels.cache
.get(OPENTICKET)
.send({ embeds: [Embed], components: [Buttons] });
interaction.reply({ content: "Done", ephemeral: true });
},
};
InitialTicket.js Code:
const { ButtonInteraction, MessageEmbed, MessageActionRow, MessageButton } = require("discord.js");
const DB = require("../../Structures/Handlers/Schemas/Ticket");
const { PARENTID, EVERYONEID } = require("../../Structures/config.json");
const Ticket = require("../../Structures/Handlers/Schemas/Ticket");
module.exports = {
name: "interactionCreate",
/**
*
* #param {ButtonInteraction} interaction
*/
async execute(interaction) {
if(!interaction.isButton()) return;
const { guild, member, customId } = interaction;
if (!["player", "bug", "other"].includes(customId)) return;
const ID = Math.floor(Math.random() * 90000) + 10000;
await guild.channels
.create(`${customId + "-" + ID}`, {
type: "GUILD_TEXT",
parent: PARENTID,
permissionOverwrites: [
{
id: member.id,
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"],
},
{
id: EVERYONEID,
deny: ["SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY"],
},
],
})
.then(async (channel) => {
await DB.create({
GuildID: guild.id,
MemberID: member.id,
TicketID: ID,
ChannelID: channel.id,
Closed: false,
Locked: false,
Type: customId,
});
const Embed = new MessageEmbed()
.setAuthor(
`${guild.name} | Ticket: ${ID}`,
guild.iconURL({ dynamic: true })
)
.setDescription(
"Please wait patiently for a response from the Staff team, in the mean while, describe your issue in as much detail."
)
.setFooter("The buttons below are staff only buttons.");
const Buttons = new MessageActionRow();
Buttons.addComponents(
new MessageButton()
.setCustomId("close")
.setLabel("Save and close")
.setStyle("PRIMARY")
.setEmoji("💾"),
new MessageButton()
.setCustomId("lock")
.setLabel("lock")
.setStyle("SECONDARY")
.setEmoji("🔒"),
new MessageButton()
.setCustomId("unlock")
.setLabel("unlock")
.setStyle("SUCCESS")
.setEmoji("🔓"),
);
channel.send({
embeds: [Embed],
components: [Buttons],
});
await channel
.send({ content: `${member} here is your ticket` })
.then((m) => {
setTimeout(() => {
m.delete().catch(() => {});
}, 1 * 3000);
interaction.reply({
content: `${member} your ticket has been created: ${channel}`,
ephemeral: true
});
});
});
},
};
If you need to see any other parts of the bot please just ask, any help is rlly appreciated.
Any questions feel free to ask and I will try answer them to the best of my ability.
I am somewhat new to JavaScript and Node.js so please be patient with me.
Are these executed from the same button press/same interaction? If so, then set the reply that happens second to interaction.followUp() or interaction.editReply (depending on whether you want a second message (followUp) or to edit the existing message (editReply)).
so I have this lockdown command I just made, but when I want to start the bot I get the following error
DiscordAPIError: Invalid Form Body
3.options[1].type: This field is required
I tried fixing it but I have no idea where the issue is.
It exists of 4 files.
File 1: GiveawaySys.js <-- system file
const { GiveawaysManager } = require('discord-giveaways');
const giveawayModel = require("../Structures/Schemas/GiveawayDB");
module.exports = (client) => {
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
async getAllGiveaways() {
return await giveawayModel.find().lean().exec();
}
async saveGiveaway(messageId, giveawayData) {
await giveawayModel.create(giveawayData);
return true;
}
async editGiveaway(messageId, giveawayData) {
await giveawayModel.updateOne({ messageId }, giveawayData, { omitUndefined: true }).exec();
return true;
}
async deleteGiveaway(messageId) {
await giveawayModel.deleteOne({ messageId }).exec();
return true;
}
};
const manager = new GiveawayManagerWithOwnDatabase(client, {
default: {
botsCanWin: false,
embedColor: '#FF0000',
embedColorEnd: '#000000',
reaction: '🎉'
}
});
client.giveawaysManager = manager;
}
File 2: Lockdown.js <-- Schema
const { model, Schema } = require("mongoose");
module.exports = model("Lockdown", new Schema({
GuildID: String,
ChannelID: String,
Time: String,
})
);
File 3: lock.js <-- lock command
const {
CommandInteraction,
MessageEmbed
} = require("discord.js");
const DB = require("../../Structures/Schemas/LockDown");
const ms = require("ms");
module.exports = {
name: "lock",
description: "Lockdown this channel",
permission: "MANAGE_CHANNELS",
options: [{
name: "time",
description: "Expire date for this lockdown (1m, 1h, 1d)",
type: "STRING",
},
{
name: "reason",
description: "Provide a reason for this lockdown.",
tyoe: "STRING",
},
],
/**
*
* #param {CommandInteraction} interaction
*/
async execute(interaction) {
const {
guild,
channel,
options
} = interaction;
const Reason = options.getString("reason") || "no specified reason";
const Embed = new MessageEmbed();
if (!channel.permissionsFor(guild.id).has("SEND_MESSAGES"))
return interaction.reply({
embeds: [Embed.setColor("RED").
setDescription("⛔ | This channel is already locked."),
],
ephemeral: true,
});
channel.permissionOverwrites.edit(guild.id, {
SEND_MESSAGES: false,
});
interaction.reply({
embeds: [Embed
.setColor("RED")
.setDescription(`🔒 | This channel is now under lockdown for: ${Reason}`
),
],
});
const Time = options.getString("time");
if (Time) {
const ExpireDate = Date.now() + ms(Time);
DB.create({
GuildID: guild.id,
ChannelID: channel.id,
Time: ExpireDate
});
setTimeout(async () => {
channel.permissionOverwrites.edit(guild.id, {
SEND_MESSAGES: null,
});
interaction.editReply({
embeds: [Embed
.setDescription("🔓 | The lockdown has been lifted")
.setColor("GREEN")
],
})
.catch(() => {});
await DB.deleteOne({
ChannelID: channel.id
});
}, ms(Time));
}
},
};
File 4: unlock.js <-- unlock command
const {
CommandInteraction,
MessageEmbed
} = require("discord.js");
const DB = require("../../Structures/Schemas/LockDown");
module.exports = {
name: "unlock",
description: "Lift a lockdown from a channel",
permission: "MANAGE_CHANNELS",
/**
*
* #param {CommandInteraction} interaction
*/
async execute(interaction) {
const {
guild,
channel
} = interaction;
const Embed = new MessageEmbed();
if (channel.permissionsFor(guild.id).has("SEND_MESSAGES"))
return interaction.reply({
embeds: [Embed
.setColor("RED")
.setDescription("⛔ | This channel is not locked"),
],
ephemeral: true,
});
channel.permissionOverwrites.edit(guild.id, {
SEND_MESSAGES: null,
});
await DB.deleteOne({
ChannelID: channel.id
});
interaction.reply({
embeds: [Embed
.setColor("GREEN")
.setDescription("🔓 | Lockdown has been lifted."),
],
});
},
};
Please help me with this one, I can't find the issue here
The error you are getting (.options[1].type is required) is a very big hint as to what the issue is. Searching the code of your files, I saw this in your third file in options[1]:
{
name: "reason",
description: "Provide a reason for this lockdown.",
tyoe: "STRING",
}
Notice the problem? It's a typo. "tyoe" instead of "type", causing djs to complain about "type" being required.
So I made a discord selection menu ticket that when I select that category it makes a channel and send a message with a button. The button is supposed to delete the channel when pressed, but it doesn't seem to work. I think I have found the error but I don't know how to fix it. It is probably easy to fix but I'm stuck.
The code: (I think the error is located in the end here)
} else if (Discord.MessageButton.customId === 'del') {
const channel = message.guild.channel
channel.delete();
const Discord = require("discord.js");
const { MessageSelectMenu, MessageActionRow } = require("discord.js");
module.exports = {
name: "ticket",
author: "Falcone",
run: async(client, message, args) => {
if (!message.member.permissions.has("ADMINISTRATOR")) return message.reply('You Dont Have the `ADMINISTRATOR` permision');
message.delete();
let embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setDescription(`Test`)
.setThumbnail(message.guild.iconURL({ dynamic: true }))
.setAuthor(message.guild.name, message.guild.iconURL({ dynamic: true }));
let painel = new MessageActionRow().addComponents( new MessageSelectMenu()
.setCustomId('menu')
.setPlaceholder('Test') // Mensagem estampada
.addOptions([
{
label: 'Support',
description: '',
emoji: '🙋♂️',
value: '1',
},
{
label: 'Test',
description: '',
emoji: '⛔',
value: '2',
},
{
label: 'Test',
description: '',
emoji: '🤖',
value: '3',
}
])
);
message.channel.send({ embeds: [embed], components: [painel] }).then(msg => {
const filtro = (interaction) =>
interaction.isSelectMenu()
const coletor = msg.createMessageComponentCollector({
filtro
});
coletor.on('collect', async (collected) => {
let ticket = collected.values[0]
collected.deferUpdate()
if (ticket === "1") {
const embed = new Discord.MessageEmbed()
.setTitle('Ticket')
.setDescription('Hello there, \n The staff will be here as soon as possible mean while tell us about your issue!\nThank You!')
.setColor('GREEN')
.setTimestamp()
const del = new MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('del')
.setLabel('🗑️ Delete Ticket!')
.setStyle('DANGER'),
);
message.guild.channels.create(`${collected.user.id}`, {
type : 'GUILD_TEXT',
permissionOverwrites : [
{
id : message.guild.id,
deny : ['VIEW_CHANNEL']
},
{
id : collected.user.id,
allow : ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES']
}
]
}).then(async (msg) => {
msg.send({ embeds: [embed], components: [del] }).then(msg => msg.pin() );
})
} else if (Discord.MessageButton.customId === 'del') {
const channel = message.guild.channel
channel.delete();
}
})
});
}
}
MessageButton.customId is not a static property. That means it must be done on an instance, not the class. Something that you could try is this:
const msg = await message.channel.send({
content: "Which one?",
components: [
new Discord.MessageActionRow().addComponents([
new Discord.MessageButton().setLabel("Delete").setStyle("DANGER").setCustomId("DEL"), //delete button
new Discord.MessageButton().setLabel("Cancel").setStyle("DANGER").setCustomId("CAN") //cancel button
])
]
})
//Create button collector
const collector = msg.createMessageComponentCollector({
componentType: "BUTTON",
filter: (c) => c.member.id === msg.member.id,
max: 1
})
//Handle button click
collector.on("collect", i => {
if(i.customId === "CAN") return i.reply("Cancelled")
if(i.customId === "DEL") i.channel.delete() //or whatever channel you want to delete
})
Warning: I did not test this code. You can tell me any problems you have and I will try to modify this
I made a &bot-info command but every time I use it, it says it is on 0 servers, with 0 channels with 0 users, how would I fix this issue? I have a similar line of code in the begining when the bot turns on telling me the amount of servers ,channels and users hes in and it works fine
const Discord = require('discord.js')
const client = new Discord.Client();
async function execute(message, args) {
const embed = new Discord.MessageEmbed()
.setTitle('Bot Stats')
.setColor('#000000')
.addFields(
{
name: '🌐 Servers',
value: `Serving ${client.guilds.cache.size} servers.`,
inline: true
},
{
name: '📺 Channels',
value: `Serving ${client.channels.cache.size} channels.`,
inline: true
},
{
name: '👥 Server Users',
value: `Serving ${client.users.cache.size}`,
inline: true
}
)
await message.channel.send(embed)
}
module.exports = {
name: 'bot-info',
description: 'bot information',
execute
}
You can try to adjust this simple solution for your code, which worked for me, or give more details why do you want to use the async function.
const Discord = require('discord.js')
const client = new Discord.Client()
client.on("message", async message => {
if(message.content === "&bot-info") {
const embed = new Discord.MessageEmbed()
.setTitle('Bot Stats')
.setColor('#000000')
.addFields(
{
name: '🌐 Servers',
value: `Serving ${client.guilds.cache.size} servers.`,
inline: true
},
{
name: '📺 Channels',
value: `Serving ${client.channels.cache.size} channels.`,
inline: true
},
{
name: '👥 Server Users',
value: `Serving ${client.users.cache.size}`,
inline: true
}
)
message.channel.send(embed)
}
})
The Problem Here Is The Guilds.cache only works on index.js for some reason I tried doing the same thing on my command handler but still it's saying 0 for me to so if you want it to work put this command in your index.js or bot.js