So i already asked around here and there but i dont find out how to fix eroor: ReferenceError: send is not defined In the non embed version everything works fine but here it just won't.
module.exports = {
name: 'lat2',
description: 'Let the Bot display latency/Response Time and API latency/"Remote Response time"',
execute(message, args) {
const Discord = require('discord.js');
let Embed1 = new Discord.MessageEmbed()
.setColor(0x0099ff)
.setDescription("Pinging...")
let Embed2 = new Discord.MessageEmbed()
.setColor(0x0099ff)
.setTitle("Latencies")
.setDescription(`Latency/Response Time: ${send.createdTimestamp - message.createdTimestamp}ms\nAPI latency/"Remote Response time": ${Math.round(message.client.ws.ping)}ms`)
msg.channel.send(Embed1).then(msg => {
msg.edit(Embed2);
});
}
};
The problem isn't sending the message, it's complaining about the ${send.createdTimestamp}, because you didn't define "send" anywhere there.
Try replacing it with message.createdAt
To still get the Latency, try this:
module.exports = {
name: 'lat2',
description: 'Let the Bot display latency/Response Time and API latency/"Remote Response time"',
execute(message, args) {
const Discord = require('discord.js');
let Embed1 = new Discord.MessageEmbed()
.setColor(0x0099ff)
.setDescription("Pinging...")
msg.channel.send(Embed1).then(m => {
let Embed2 = new Discord.MessageEmbed()
.setColor(0x0099ff)
.setTitle("Latencies")
.setDescription(`Latency/Response Time: ${m.createdTimestamp - message.createdTimestamp}ms\nAPI latency/"Remote Response time": ${Math.round(message.client.ws.ping)}ms`)
m.edit(Embed2);
});
}
};
Related
I wrote a new command when my bot ran on my pc and not a server.
While the bot ran on my pc the command worked very well, but after I put my bot into a server
the command stopped working and I always get an error message:
DiscordAPIError: Cannot send an empty message
The code:
const Discord = require("discord.js");
const recon = require('reconlx');
const rpages = recon.ReactionPages
const moment = require('moment');
const fs = require('fs');
module.exports = class HelpCommand extends BaseCommand {
constructor() {
super('help', 'moderation', []);
}
async run(client, message, args) {
const y = moment().format('YYYY-MM-DD HH:mm:ss')
const sayEmbed1 = new Discord.MessageEmbed()
.setTitle(`example`)
const sayEmbed2 = new Discord.MessageEmbed()
.setTitle(`example`)
const sayEmbed3 = new Discord.MessageEmbed()
.setTitle(`example`)
const sayEmbed5 = new Discord.MessageEmbed()
.setTitle(`example`)
const sayEmbed4 = new Discord.MessageEmbed()
.setTitle(`example`)
const sayEmbed6 = new Discord.MessageEmbed()
.setTitle(`example`)
.setDescription("[A készítőm Weboldala](https://istvannemeth1245.wixsite.com/inde/)\n\n")
try {
await
message.delete();
const pages = [{ embed: sayEmbed1 }, { embed: sayEmbed2 }, { embed: sayEmbed3 }, { embed: sayEmbed4 }, { embed: sayEmbed5 }, { embed: sayEmbed6 }];
const emojis = ['◀️', '▶️'];
const textPageChange = true;
rpages(message, pages, textPageChange, emojis);
} catch (err) {
console.log(err);
message.channel.send('Nem tudom ki írni az üzenetet');
}
const contetn = `\n[${y}] - ${message.author.username} használta a help parancsot. `;
fs.appendFile('log.txt', contetn, err => {
if (err) {
console.err;
return;
}
})
}
}
Full error message:
throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/home/container/Lee-Goldway/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (/home/container/Lee-Goldway/node_modules/discord.js/src/rest/RequestHandler.js:39:14) {
method: 'post',
path: '/channels/833629858210250813/messages',
code: 50006,
httpStatus: 400
}
A couple of things. Are you sure that this reconlx package is compatible with your discord.js version? It's always a good idea to post your discord.js version when you have a problem with libraries.
If you're using reconlx v1, you can see in their old documentation that in ReactionPages the second parameter takes an array of embeds. If you check the source code, you can see that it tries to send the first item of pages as an embed, like this: message.channel.send({ embeds: [pages[0]] }).
It means that with your code embeds is an array where the first item is an object that has an embed key with the sayEmbed1 embed, while discord.js accepts an array of MessageEmbeds.
I would try to pass down an array of embeds like this:
const pages = [
sayEmbed1,
sayEmbed2,
sayEmbed3,
sayEmbed4,
sayEmbed5,
sayEmbed6,
];
PS: ki írni is incorrect. When the verb particle precedes the verb, they are written as one word. So, it should be kiírni. :)
In the code provided, there appears to be no code that references "{embeds:[embed]}".
However, assuming the error is coming from this line:
message.channel.send('Nem tudom ki írni az üzenetet');
Referring to the official documentation, you can provide an object.
For example:
message.channel.send({ content: 'Nem tudom ki írni az üzenetet' });
Well the code below works fine but the only problem is the bot do not play the full track, so is it even possible to play many hours like 22 hours? any ideas?
I hope I did a great job explaining the problem
node v12.22.10
discord.js v12.5.3
command file test.js:
const ytdl = require('ytdl-core');
const Discord = require('discord.js')
const client = new Discord.Client()
module.exports = {
commands: 'test',
callback: (message, arguments, text, client) => {
const url = 'url here';
if (message.content == '!test') {
if (!message.member.voice.channel) return message.reply("you need to be on a voice channel to play the audio");
message.member.voice.channel.join().then(VoiceConnection => {
VoiceConnection.play(ytdl(url)).on("finish", () =>
VoiceConnection.disconnect());
const logo =
'url here'
const thumb = 'url here'
const embed = new Discord.MessageEmbed()
.setTitle('Playing...')
.setAuthor(message.author.username)
.setTimestamp()
.setThumbnail(thumb)
.setFooter("xx", logo)
.setColor('#447a88')
message.reply(embed)
}).catch(e => console.log(e))
}
}
}
I'm making a discord bot and one of the commands is a kick command, so the problem is when you input "=kick info" its supposed to display an embed that will give you information about the command and it keeps giving me the error
DiscordAPIError: Invalid Form Body user_id: Value "info" is not snowflake.
It used to work just fine, but for some reason it started to give me this error, not only with this command but with all the others as well.
I tried to make a separate command that would display the embed if you typed =info "command" but that didn't work, if there is a fix for this please do let me know.
Here is the code:
const Discord = require('discord.js')
module.exports = {
name: 'kick',
description: 'Use this command to kick a member from the server so that they have to recieve an invite to re-join it.',
async execute(client, message, args) {
let PermissionEmbed = new Discord.MessageEmbed()
.setDescription(":no_entry: **You do not have Permission to use this command.**")
.setColor('#FF0000');
let PermissionEmbed2 = new Discord.MessageEmbed()
.setDescription(":no_entry: **I do not have Permission to Kick members.**")
.setColor('#FF0000');
if(!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send(PermissionEmbed);
if(!message.guild.me.hasPermission("KICK_MEMBERS")) return message.channel.send(PermissionEmbed2);
let reason = args.slice(1).join(" ");
const mentionedMember = message.mentions.members.first() || await message.guild.members.fetch(args[0]);
let yes = 'info'
let ErrorEmbed = new Discord.MessageEmbed()
.setDescription(":no_entry: **User could not be kicked, the user's role is higher than mine**")
.setColor('#FF0000');
let ErrorEmbed2 = new Discord.MessageEmbed()
.setDescription(":no_entry: **User could not be kicked, the user's role is higher than Yours**")
.setColor('#FF0000');
let ErrorEmbed3 = new Discord.MessageEmbed()
.setDescription(":no_entry: **You cannot kick me.**")
.setColor('#FF0000');
let ErrorEmbed4 = new Discord.MessageEmbed()
.setDescription(":no_entry: **You cannot kick yourself.**")
.setColor('#FF0000');
const KickedEmbed = new Discord.MessageEmbed()
.setDescription(':white_check_mark: **Successfully Kicked '+mentionedMember.user.tag+'**')
.setColor('2eb82e')
const Embedhelp = new Discord.MessageEmbed()
.setTitle('Kick Command')
.setColor('#6DCE75')
.setDescription('**Description**\nUse this command to kick a member from the server so that they have to recieve an invite to re-join it')
.addFields(
{ name: '**Usage:**', value: '=kick (user) (reason)'},
{ name: '**Example:**', value: '=kick #Michael gtfo'},
{ name: '**Info**', value: 'I cannot kick members that have a higher role than me\nYou cannot kick members that have a higher role than you.\nYou cannot kick me.\nYou cannot kick yourself'}
)
.setFooter(client.user.tag, client.user.displayAvatarURL());
if (!reason) reason = 'No reason given';
if (!args[0]) return message.channel.send(Embedhelp);
if (args[0] === yes.toLowerCase)
if (!mentionedMember) return message.channel.send(Embedhelp);
if (!mentionedMember.kickable) return message.channel.send(ErrorEmbed);
if (mentionedMember.user.id == message.author.id) return message.channel.send(ErrorEmbed4);
if (mentionedMember.user.id == client.user.id) return message.channel.send(ErrorEmbed3);
if (message.member.roles.highest.position <= mentionedMember.roles.highest.position) return message.channel.send(ErrorEmbed2)
const kickEmbed = new Discord.MessageEmbed()
.setTitle('You have been Kicked from '+message.guild.name)
.setDescription('Reason for Kick: '+reason)
.setColor('#6DCE75')
.setTimestamp()
.setFooter(client.user.tag, client.user.displayAvatarURL());
await mentionedMember.send(kickEmbed).catch(err => console.log(err));
await mentionedMember.kick({
days: 7,
reason: reason
}).catch(err => console.log(err)).then(() => message.channel.send(KickedEmbed));
}
}
I tried searching online for a fix but couldn't find any that worked.
If your message content is =kick info, args[0] is the string "info". When you try to fetch the member using message.guild.members.fetch(args[0]) it sends a request where the user_id is "info" which is not a valid snowflake.
A quick fix would be to check the value of args[0] earlier and return if it's "info":
module.exports = {
name: 'kick',
description:
'Use this command to kick a member from the server so that they have to recieve an invite to re-join it.',
async execute(client, message, args) {
if (args[0] === 'info')
return message.channel.send('Some info about this command...')
let PermissionEmbed = new Discord.MessageEmbed()
// ...
I'm trying to get the Discord username of the person banned in the unban script, but it doesn't work. I tried all kinds of things, but could you help?
const Discord = require("discord.js");
const client = new Discord.Client();
exports.run = (client, message, args) => {
if (!message.guild) {
const ozelmesajuyari = new Discord.RichEmbed()
.setColor(0xff0000)
.setTimestamp()
.setAuthor(message.author.username, message.author.avatarURL)
.addField(":warning: Uyarı :warning:", "`unban` adlı komutu özel mesajlarda kullanamazsın.");
return message.author.sendEmbed(ozelmesajuyari);
}
let guild = message.guild;
let reason = args.slice(1).join(" ");
client.unbanReason = reason;
client.unbanAuth = message.author;
let user = client.users.fetch(args[0]);
let modlog = guild.channels.find("name", "bot-log");
if (!modlog) return message.reply("`bot-log` kanalını bulamıyorum.");
if (reason.length < 1) return message.reply("Ban kaldırma sebebini yazmalısın.");
if (!user) return message.reply("Banı kaldırılacak kişinin ID numarasını yazmalısın.").catch(console.error);
message.guild.unban(user);
const embed = new Discord.RichEmbed()
.setColor(0x00ae86)
.setTimestamp()
.addField("Eylem:", "Ban kaldırma")
.addField("Kullanıcı:", `${user.name}#${user.discriminator} (${user.id})`)
.addField("Yetkili:", `${message.author.username}#${message.author.discriminator}`)
.addField("Sebep", reason);
return guild.channels.get(modlog.id).send(embed);
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: [],
permLevel: 4,
};
exports.help = {
name: "unban",
description: "İstediğiniz kişinin banını kaldırır.",
usage: "unban [kullanıcı] [sebep]",
};
First off, Welcome to Stack Overflow!
I believe you'll find an answer to your question here.
When you have an error, try searching for the error first, as it is likely that you aren't the first person to come across it.
To sum up the linked answer, try unbanning by just the user ID rather than a user object.
Also, ensure that you're using the correct syntax for your discord.js version. It is highly suggested that you migrate to disord.js v12, see the migration guide.
(Türkçe olarak)
Öncelikle, Stack Overflow'a Hoş Geldiniz!
Burada sorunuzun cevabını bulacağınıza inanıyorum.
Bir hatayla karşılaştığınızda, muhtemelen ilk karşılaşan kişi siz olmadığınız için önce hatayı aramayı deneyin.
Bağlantılı yanıtı özetlemek için, kullanıcı nesnesi yerine yalnızca kullanıcı kimliğiyle yasağı kaldırmayı deneyin.
Ayrıca, discord.js sürümünüz için doğru sözdizimini kullandığınızdan emin olun. Discord.js v12'ye geçiş yapmanız kesinlikle önerilir, geçiş kılavuzuna bakın.
So I am trying to make a raffle command for my discord bot. I kinda have two questions I am trying to make it have a winner based on who reacted to that message here is what I have so far
const discord = require("discord.js")
const bot = new discord.Client();
module.exports.run = async (bot, message, args) => {
if (!message.member.hasPermission("MANAGE_CHANNELS")) return message.reply("sorry you dont have permission to use this command"); {
const embed = new discord.RichEmbed()
.setTitle('Raffle')
.addField('React to the message with a thumbs up to enter!', "Time for some fun!")
message.channel.send(embed).then(function (message) {
message.react('👍')
});
bot.on('messageReactionAdd', (reaction, user) => {
const user1 = reaction.random
const embed1 = new discord.RichEmbed()
.setTitle('Winner!!')
.addField(`${user1}`, "you are the winner!!")
message.channel.send(embed1);
});
}
}
module.exports.help = {
name: "Raffle",
name: "raffle"
}
So user1 keeps returning undefined thanks in advance and by the way I am semi new to JavaScript
In your code, you set user1 to reaction.random:
const user1 = reaction.random
reaction.random isn't a valid method of MessageReaction, and therefore, when you send the message, user1 is undefined.