Discord.JS List item values of ModelType are required - discord.js

I'm making a message content logging for my own server bot to logs all the message will be sent inside the server including embeds and pictures and gif but pics and gif when sending those (directly not by link) using upload files on discord it prompt this error:
DiscordAPIError[50035]: Invalid Form Body
embeds[0][LIST_ITEM_VALUE_REQUIRED]: List item values of ModelType are required
I'm using discord.js v14
This is my code
const Discord = require('discord.js');
const { WebhookClient } = require('discord.js');
const client = require('../index');
const wbc = new WebhookClient({
id: "",
token: "",
});
module.exports = {
name: 'messageCreate',
async execute(message) {
// if (message.channel.id === "999954713887907870") {
if (message.channel.id === "1003856060647477298") return;
let content = message.content ? message.content : { embeds: [message.embeds[0]] };
wbc.send(content)
}
// }
}
If you want to see the whole error message you can click here.

Related

Sharpjs throws error: Input file is missing

I have a discord bot
Code:
const Discord = require('discord.js');
const sharp = require('sharp');
const client = new Discord.Client({ intents: ["Guilds", "GuildMessages", "MessageContent"] });
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`)
})
client.on('messageCreate', async message => {
if (!message.content.startsWith('!rights') || message.author.bot) return;
console.log("invoked");
// get image link or image attachment
let imageUrl = '';
if (message.attachments.size > 0) {
imageUrl = message.attachments.first().url;
} else {
return message.reply('Please provide an image link or attach an image to the message.');
}
// open image using sharp
let image;
try {
image = await sharp(imageUrl);
} catch (error) {
return message.reply('Invalid image URL or file type.');
}
// add text to image
const text = 'Hello World';
image = await image.composite([{
input: Buffer.from(text),
gravity: 'center'
}])
// send edited image in message
const buffer = await image.toBuffer();
console.log("Sending");
message.channel.send(new Discord.MessageAttachment(buffer));
});
the error says that the image I passed which is a discord image link is missing
I tried different images but the issue is still the same

Embed stated not being sent to channel

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
});
const { EmbedBuilder } = require('discord.js');
// All partials are loaded automatically
//const Discord = require('discord.js');
client.on('ready', async () => {
console.log(`${client.user.username} is ready!`);
})
client.on('guildCreate', (g) => {
const channel = g.channels.cache.find(channel => channel.type === 'GUILD_TEXT' && channel.permissionsFor(g.me).has('SEND_MESSAGES'))
channel.send("Thanks for inviting flappy dank! Please run the command !run to get started!");
})
client.on("messageCreate", async (message) => {
if (message.content == '!testcmd') {
const illla = new EmbedBuilder()
.setColor(FF0000)
.setTitle('Members Generator 2.0!')
.setDescription('testing testing 123 123')
.setTimestamp()
.setFooter({ text: 'wow a footer'});
message.channel.send(illla)
}
})
I have tried the code above, when I run the command ‘!testcmd’, it does not output any embed. i have searched online for solutions, but none working. I expect and embed to be outputted, yet it doesn’t return any errors. Any advice would be appreciated!
You're using discord.js v14. There's a changes about sending Embeds
const illla = new EmbedBuilder()
.setColor(FF0000)
.setTitle('Members Generator 2.0!')
.setDescription('testing testing 123 123')
.setTimestamp()
.setFooter({ text: 'wow a footer'});
message.channel.send(illla) //The Changes is in here
The comment line should change as:
message.channel.send({embeds: [illla] });
Click here to see more about EmbedBuilder

DiscordJS 403 Error Missing Access Error when trying to add Slash Commands

I am following the docs at DiscrodJS step by step and have been able to invite my bot just fine to my test server. My problem comes in when I try to add the slash commands.
Here is my index.js file.
const { Client, GatewayIntentBits } = require('discord.js')
require('dotenv').config()
const client = new Client({
intents: [
GatewayIntentBits.GuildMessages,
],
})
client.once('ready', () => {
console.log('Ready!')
})
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return
const { commandName } = interaction
const command = interaction.client.commands.get(commandName)
if (!command) {
console.error(`No command matching ${commandName} was found.`)
return
}
try {
await command.execute(interaction)
}
catch (error) {
console.error(error)
await interaction.reply({ ontent: 'There was an error while executing this command', ephemeral: true })
}
})
client.login(process.env.DISCORD_PRIVATE_TOKEN)
Here is my deploy-commands.js file.
const fs = require('node:fs')
const { Routes } = require('discord.js')
const { REST } = require('#discordjs/rest')
require('dotenv').config()
const {
DISCORD_PRIVATE_TOKEN,
DISCORD_CLIENT_ID,
DISCORD_GUILD_ID,
} = process.env
const commands = []
// Grab all the command files from the commands directory you created earlier
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'))
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./commands/${file}`)
commands.push(command.data.toJSON())
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(DISCORD_PRIVATE_TOKEN)
// and deploy your commands!
const deployCommand = async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`)
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(DISCORD_CLIENT_ID, DISCORD_GUILD_ID),
{ body: commands },
)
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
}
catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error)
}
}
deployCommand()
There error that I get back from this is the following:
requestBody: { files: undefined, json: [ [Object] ] },
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/[client_id]/guilds/[guild_id]/commands'
}
In the bot settings
I've set auth method to In-app Authorization.
I've set the scope to bot and applications.commands then included Use Slash Commands (also tried this with ALL including Administrator bot permissions.
I've also done this through the URL Generator path.
In my discord server
I've put my Discord server into Developer mode to test my bot.
I've invited my bot to my test server.
In my code
I've ran the one time script for deploy-commands.js.

DM Specific User ID on Discord.js Bot

i'm new to coding bots and i need help on how to add a command on messaging a certain person a customized message. this is what i have so far. what should i do?
const Discord = require('discord.js');
const config = require("./Data/config.json")
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
client.once('ready', () => {
console.log('Ready!');
});
client.login('TOKEN');
client.on('message', async message => {
if (message.author.bot) return;
let prefix = '??'
if (!message.content.startsWith(prefix)) return;
let args = message.content.slice(prefix.length).trim().split("/ +/g");
let msg = message.content.toLowerCase();
let cmd = args.shift().toLowerCase();
if (msg.startsWith(prefix + 'ping')) {
message.channel.send('pong');
}
if (msg.startsWith(prefix + 'hello')) {
message.channel.send('hewwo uwu');
}
});
To fetch a user by id, you can use bot.users.fetch()
To direct message a user, you can use User.send():
const user = await client.users.fetch(userId);
user.send("This is a DM!");
This simple function will easily resolve the user (you can provide a user object or user ID so it’s very helpful)
async function DMUser(resolvable, content, client) {
const user = client.users.resolve(resolvable)
return user.send(content)
}
//returns: message sent, or error
//usage: DMUser(UserResolvable, "content", client)
Related links:
UserManager.resolve
User.send
UserResolvable

My discord bot isn't working after 13.0.0

I am trying out discord.js version 13.1.0 and I am following discord's guide on how to setup a bot. I have followed all the steps. When I have the bot running, and I send a message or a command into the server, nothing gets printed to the console. Any ideas?
My code:
const { Client, Intents } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once("ready", () => {
console.log("Ready!");
});
client.on("interactionCreate", (interaction) => {
console.log(interaction);
});
client.login(process.env.TOKEN);
From the Discord Developer Portal:
An Interaction is the message that your application receives when a user uses an application command or a message component.
By an application command is meant a special type of command, that you have to register against the Discord API. To learn more about application commands, read this.
From the discord.js docs main page, how to register an application (slash) command:
const { REST } = require('#discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [{
name: 'ping',
description: 'Replies with Pong!'
}];
const rest = new REST({ version: '9' }).setToken('token');
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
However if you are looking for a way to reply to (or just capture) a normal message sent in a TextChannel, you are probably looking for the messageCreate event.
client.on("messageCreate", (message) => {
console.log(message);
});
Also note that to receive messageCreate event, you need GUILD_MESSAGES intent.
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

Resources