'message.reply not defined' discord.js v13 - discord.js

So I'm creating a bot with a handler online, and I'm trying to send an embed through message.reply, but it comes and error saying 'reply' is not defined. Here is the code:
const { Discord, MessageEmbed } = require('discord.js')
module.exports = {
callback: async ({ client, message, ...args }) => {
const embed = new MessageEmbed()
.setAuthor({
name: 'ยป Ping',
iconURL: client.user.defaultAvatarURL
})
.setTitle('Calculating ping...')
.setColor('GREEN')
message.reply({
embeds: [embed]
})
}
}
And here is the handler:
const fs = require('fs')
const getFiles = require('./get-files')
module.exports = (client) => {
const commands = {}
const suffix = '.js'
const commandFiles = getFiles('./commands', suffix)
for (const command of commandFiles) {
let commandFile = require(command)
if (commandFile.default) commandFile = commandFile.default
const split = command.replace(/\\/g, '/').split('/')
const commandName = split[split.length - 1].replace(suffix, '')
commands[commandName.toLowerCase()] = commandFile
}
client.on('messageCreate', (message) => {
if (message.author.bot || !message.content.startsWith('!')) {
return
}
const args = message.content.slice(1).split(/ +/)
const commandName = args.shift().toLowerCase()
if (!commands[commandName]) {
return
}
try {
commands[commandName].callback(client, message, ...args)
} catch (err) {
console.error('[ERROR]', err)
}
})
}
I would appreciate if you found out.
Thanks!

Related

discord js v13 message reply don't work (prefix)

I was making discord bot that reply the user word with prefix.
example the user said !Hello the bot will reply with Hello
The error was
(node:11208) DeprecationWarning: The message event is deprecated. Use messageCreate instead (Use node --trace-deprecation ... to show where the warning was created)
So I changed the code message to messageCreate but the bot didn't reply either and have no error in the console log what should I change the code of my script?
this is the source code
prefix is ! (It is in the config.json)
index.js
const {Client,Intents,Collection} = require("discord.js");
const client = new Client ({intents:[Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES,Intents.FLAGS.GUILD_MEMBERS]})
const fs = require("fs");
const { token, prefix } = require("./config.json");
client.commands = new Collection();
const commandFiles = fs.readdirSync("./commands").filter((file) => file.endsWith(".js"));
var data = []
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
data.push({name:command.name,description:command.description,options:command.options});
}
client.once('ready', async () =>{
console.log(`Logged in as ${client.user.tag}`)
// await client.guilds.cache.get('874178319434801192')?.commands.set(data)
setInterval(() => {
const statuses = [
'mimc!',
'wtf',
'prefix = !'
]
const status = statuses[Math.floor(Math.random()*statuses.length)]
client.user.setActivity(status, {type: "PLAYING"})
}, 10000)
});
client.on("messageCreate", (message) =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift();
if(!client.commands.has(command)) return;
try{
client.commands.get(command).execute(message, args);
}
catch(error){
console.error(error);
}
});
client.login(token)
Hello.js (in the folder of commands)
module.exports = {
name: "Hello",
description: "Say Hi",
execute(message) {
return message.channel.send(`${message.author}, Hello.`)
},
};
The code of index.js (or main file) goes by:
const {Client, Intents, MessageEmbed, Presence, Collection, Interaction}= require ('discord.js')
const client = new Client({intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})
const TOKEN = ''// get your TOKEN!
const PREFIX = '!'
const fs = require('fs')
client.commands = new Collection();
const commandFiles = fs.readdirSync('commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', ()=> {
console.log('๐Ÿ• I am online!!')
client.user.setActivity('A GAME ', {type: ('PLAYING')})
client.user.setPresence({
status: 'Online'
})
})
client.on('message', message => {
if(!message.content.startsWith(PREFIX)|| message.author.bot) return
const arg = message.content.slice(PREFIX.length).split(/ +/)
const command= arg.shift().toLowerCase()
if (command === 'ping'){
client.commands.get('ping').execute(message,arg)
}
})
client.login(TOKEN)
After making a folder commands, add a new .js file, and name it as ping.js
The code for ping.js goes by -
module.exports={
name:'ping',
execute(message, arg){
message.reply('hello!!')
}
}

Discord.js - Discord bot stopped responding to commands

I was trying to add some new features to my bot, and it didn't end up working. So I removed the new code, and now it won't respond to any commands. It's still online but as I said earlier, it's completely unresponsive. I've looked through the code and I can't find the issue. I'm still new to coding bots so I'm probably missing something.
Here's my main code file:
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
console.log(message)
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(token);
And here's a command file:
function pickOneFrom(array) {
function pickOneFrom(array) {
return array[Math.floor(Math.random() * array.length)];
}
module.exports = {
name: 'throw',
description: 'this is a throw command!',
execute(message, args) {
const responses = ['a apple', 'a melon', 'a potato', 'a snowball', 'a spanner', 'a computer'];
message.channel.send(
`${message.author} threw ${pickOneFrom(responses)} at ${
message.mentions.users.first() ?? 'everyone'
}!`,
);
},
};```
After looking your code I see that you didn't import fs file system to reading commands files to import so you should add it into your code
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(token);
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(client , message , args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(token);
You forgot to add client at client.commands.get(command).execute(message , args)

Embed for music bot not working/discord.js

I'm working on my music bot for my discord server. So my code from a technical perspective works, it can play music, and it has queues, but I'm trying to add embeds to the messages, but I keep getting an error message that my message, channel, author is not defined. How do correctly define properties that I need for my embeds to work?
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');
const queue = new Map();
module.exports = {
name: 'play',
aliases: ('skip', 'stop'),
cooldown: 0,
description: 'Advanced music bot',
async execute(client, message, args, cmd, Discord){
const voice_channel = message.member.voice.channel;
if (!voice_channel) return message.channel.send('You need to be in a channel to execute this command!');
const permissions = voice_channel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct permissins');
if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct permissins');
const server_queue = queue.get(message.guild.id);
if (cmd === 'play'){
if (!args.length) return message.channel.send('You need to send the second argument!');
let song = {};
if (ytdl.validateURL(args[0])) {
const song_info = await ytdl.getInfo(args[0]);
song = { title: song_info.videoDetails.title, url: song_info.videoDetails.video_url }
} else {
const video_finder = async (query) =>{
const video_result = await ytSearch(query);
return (video_result.videos.length > 1) ? video_result.videos[0] : null;
}
const video = await video_finder(args.join(' '));
if (video){
song = { title: video.title, url: video.url }
} else {
message.channel.send('Error finding video.');
}
}
if (!server_queue){
const queue_constructor = {
voice_channel: voice_channel,
text_channel: message.channel,
connection: null,
songs: []
}
queue.set(message.guild.id, queue_constructor);
queue_constructor.songs.push(song);
try {
const connection = await voice_channel.join();
const Discord = require('discord.js');
queue_constructor.connection = connection;
video_player(message.guild, queue_constructor.songs[0]);
} catch (err) {
queue.delete(message.guild.id);
message.channel.send('There was an error connecting!');
throw err;
}
} else{
server_queue.songs.push(song);
newEmbed = new Discord.MessageEmbed()
.setTitle("**Now adding...**")
.setDescription(`${song.title}\n\`Requested by:\` ${message.author}`)
.setColor("#ff0000")
.setThumbnail('https://i.pinimg.com/474x/db/cd/d0/dbcdd0a38ebdb5f7f32cfda2f671dede.jpg')
return message.channel.send
message.channel.send(newEmbed);
}
}
}
}
const video_player = async (guild, song) => {
const song_queue = queue.get(guild.id);
if (!song) {
song_queue.voice_channel.leave();
queue.delete(guild.id);
return;
}
const stream = ytdl(song.url, { filter: 'audioonly' });
const Discord = require('discord.js');
song_queue.connection.play(stream, { seek: 0, volume: 0.5 })
.on('finish', () => {
song_queue.songs.shift();
video_player(guild, song_queue.songs[0]);
});
await song_queue.text_channel.send
newEmbed = new Discord.MessageEmbed()
.setTitle("**Now playing...**")
.setDescription(`${song.title}\n\`Requested by:\` ${message.author}`)
.setColor("#ff0000")
.setThumbnail('https://i.pinimg.com/236x/a1/57/2c/a1572c4306f27fd644ab62199def8aab.jpg')
message.channel.send(newEmbed);
}
I think you are missing the const before the "newEmbed" and you also can't have "newEmbed" twice, as it will return an error. Change it. E.g.
const newEmbed = new Discord.MessageEmbed()
Or you can have
const songList = new Discord.MessageEmbed()
The songList can be anything but just not the same for the other embeds you want.

My music play command isn't working or sending any error, how can I fix this?

I am trying to make a my bot play music, and so when I run my command, it doesn't show any error or joining the vc. however when I'm not in the vc it does send me a message telling me to execute this command after joining the vc. I do have Ytdl and YtSearch installed ofcourse, but I can't figure out how to fix this. I'm using repl btw. I'm using Aliases for the skip and stop command.
The code is below.
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');
const queue = new Map();
module.exports = {
name: 'play',
aliases: ['skip', 'stop'],
description: 'Plays music',
async execute(message, args, cmd, client, Discord){
const voice_channel = message.member.voice.channel;
if (!voice_channel) return message.channel.send('You need to be in a channel to execute this command!');
const permissions = voice_channel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct permissins');
if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct permissins');
const server_queue = queue.get(message.guild.id);
if (cmd === 'play'){
if (!args.length) return message.channel.send('You need to send the second argument!');
let song = {};
if (ytdl.validateURL(args[0])) {
const song_info = await ytdl.getInfo(args[0]);
song = { title: song_info.videoDetails.title, url: song_info.videoDetails.video_url }
} else {
const video_finder = async (query) =>{
const video_result = await ytSearch(query);
return (video_result.videos.length > 1) ? video_result.videos[0] : null;
}
const video = await video_finder(args.join(' '));
if (video){
song = { title: video.title, url: video.url }
} else {
message.channel.send('Error finding video.');
}
}
if (!server_queue){
const queue_constructor = {
voice_channel: voice_channel,
text_channel: message.channel,
connection: null,
songs: []
}
queue.set(message.guild.id, queue_constructor);
queue_constructor.songs.push(song);
try {
const connection = await voice_channel.join();
queue_constructor.connection = connection;
video_player(message.guild, queue_constructor.songs[0]);
} catch (err) {
queue.delete(message.guild.id);
message.channel.send('There was an error connecting!');
throw err;
}
} else{
server_queue.songs.push(song);
return message.channel.send(`๐Ÿ‘ **${song.title}** added to queue!`);
}
}
else if(cmd === 'skip') skip_song(message, server_queue);
else if(cmd === 'stop') stop_song(message, server_queue);
}
}
const video_player = async (guild, song) => {
const song_queue = queue.get(guild.id);
if (!song) {
song_queue.voice_channel.leave();
queue.delete(guild.id);
return;
}
const stream = ytdl(song.url, { filter: 'audioonly' });
song_queue.connection.play(stream, { seek: 0, volume: 0.5 })
.on('finish', () => {
song_queue.songs.shift();
video_player(guild, song_queue.songs[0]);
});
await song_queue.text_channel.send(`๐ŸŽถ Now playing **${song.title}**`)
}
const skip_song = (message, server_queue) => {
if (!message.member.voice.channel) return message.channel.send('You need to be in a channel to execute this command!');
if(!server_queue){
return message.channel.send(`There are no songs in queue ๐Ÿ˜”`);
}
server_queue.connection.dispatcher.end();
}
const stop_song = (message, server_queue) => {
if (!message.member.voice.channel) return message.channel.send('You need to be in a channel to execute this command!');
server_queue.songs = [];
server_queue.connection.dispatcher.end();
}

i have made a discord bot my ban commands works but my kick command is not working

const { getUserFromMention } = require("../userinfo/getuser.js");
module.exports = {
name: "kick",
description: "kick a player",
execute(message, client) {
const split = message.content.split(/ +/);
const args = split.slice(1);
const member = getUserFromMention(args[0], client);
if (!member) {
return message.reply("Say the name lets dew it !");
}
if (!message.member.permissions.has("KICK_MEMBERS")) {
return message.reply("I can't kick this user.");
}
return message.guild.members
.kick(member)
.then(() => message.reply(`${member.username} was kicked.`))
.catch((error) => message.reply("They are above my paygrade"));
},
};
You can use the kick function in the member object itself
Try this
return member.kick()
.then(() => message.reply(`${member.user.username} was kicked.`))
.catch(error => message.reply('They are above my paygrade'));
Try This
const { getUserFromMention } = require("../userinfo/getuser.js");
module.exports = {
name: "kick",
description: "kick a player",
execute(message, client) {
const split = message.content.split(/ +/);
const args = split.slice(1);
const member = getUserFromMention(args[0], client);
if (!member) {
return message.reply("Say the name lets dew it !");
}
if (!message.member.permissions.has("KICK_MEMBERS")) {
return message.reply("I can't kick this user.");
}
return member.kick()
.then(() => message.reply(`${member.user.username} was kicked.`))
.catch(error => message.reply('They are above my paygrade'));
},
};

Resources