signal: segmentation fault (core dumped) - discord.js

I posted about this a few days ago, but after following their suggestion it still does not seem to be working. Any idea why? I am using replit and uptime to host the bot.
I am new to coding and I just can't figure out whats wrong
Figured I would ask you guys and see if you have any idea why. Please lemme know if you have any ideas
const prefix = '?';
const Discord = require('discord.js');
const { MessageEmbed } = require('discord.js');
const bot = new Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES"
]
});
const config = process.env;
bot.on('ready', () => {
console.log(bot.user.username + ' is online.')
});
//CONSTANT COMMANDS
//Text Commands
bot.on('messageCreate', (msg) => {
if(msg.author.bot || msg.channel.type === "dm")
return;
const messageArray = msg.content.split(' ');
const cmd = messageArray[0];
const args = msg.content.substring(msg.content.indexOf(' ') + 1);
const prefix = config.prefix;
if(cmd.toLowerCase() === prefix + 'discord' ) {
msg.channel.send({
content: 'https://discord.gg/RehTqdDpEm'
})
}
if(cmd.toLowerCase() === prefix + 'realm' ) {
msg.channel.send({
content: 'https://realms.gg/5T7DrRwbS7o'
})
}
if(cmd.toLowerCase() === prefix + 'yada' ) {
msg.channel.send({
content: 'yada'
})
}
//Embed Commands
if(message.content.toLowerCase() === prefix + "help") {
let embed = new MessageEmbed()
.setTitle("Command List")
.setDescription("**?Player Description**- Shows a description of all the players. \n **realm**- Sends a realm invite \n **?factions**- Shows the factions of this season and their members \n **?info {faction}**- Shows the lore and banner of a faction \n **?help**- Shows this help menu \n **?quote**- Sends a random quote from the server \n **?world**- sends the world lore.")
.setColor("RANDOM")
message.channel.send({ embeds: [embed]})
}
if(message.content.toLowerCase() === prefix + "world") {
let embed2 = new MessageEmbed()
.setTitle("World Lore")
.setDescription("lore")
.setColor("RANDOM")
message.channel.send({ embeds: [embed2]})
}
if(message.content.toLowerCase() === prefix + "info giraduan") {
let embed2 = new MessageEmbed()
.setTitle("The Giraduan Dominion")
.setDescription("lore")
.setColor("RANDOM")
message.channel.send({ embeds: [embed2]})
}
if(message.content.toLowerCase() === prefix + "info rpa") {
let embed2 = new MessageEmbed()
.setTitle("Rerualin Preservation Association")
.setDescription("faction lore")
.setColor("RANDOM"
)
message.channel.send({ embeds: [embed2]})
}
if(message.content.toLowerCase() === prefix + "player description") {
let embed2 = new MessageEmbed()
.setTitle("Player Descriptions")
.setDescription("oops no info for you")
.setColor("RANDOM")
message.channel.send({ embeds: [embed2]})
}
if(message.content.toLowerCase() === prefix + "character example") {
let embed2 = new MessageEmbed()
.setTitle("Example Character")
.setDescription("description")
.setColor("RANDOM")
.setThumbnail('https://cdn.discordapp.com/attachments/877727121341026304/904443409614401546/YIN_YANG-removebg-preview.png')
message.channel.send({ embeds: [embed2]})
}
});
//Game Commands
bot.login(config.token);

Related

DiscordAPIError: Cannot send an empty message (discord.js v13)

I am coding a bot with the below command and it throws an error, but i don't know where is the error
i tried my best
const Discord = require("discord.js");
const client = new Discord.Client({
allowedMentions: {
parse: ["roles", "users", "everyone"],
},
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.DIRECT_MESSAGES
]
});
const config = require("../config.json");
module.exports = {
name: "quar",
run: async (client, message, args) => {
if (!message.member.permissions.has("ADMINISTRATOR")) return;
let role = message.guild.roles.cache.find(role => role.name === "Quarantined" || role.name === "Quarantine")
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = message.content.split(" ").slice(2).join(" ")
if(!reason) reason = "No reason given."
if(!role) return message.channel.send("❌ This server doesn't have a quarantine role!")
if(!member) return message.channel.send("❌ You didn't mention a member!")
if(member.roles.cache.has(role.id)) return message.channel.send(`❌ That user already quarantined!`)
member.roles.add(role)
.then (() => {
const embed = new Discord.MessageEmbed()
.setTitle(`✅ ${member.user.tag} was quarantined!`)
.setColor("RANDOM")
.setTimestamp()
embed.setFooter(`Requested by ${message.author.username}`)
message.channel.send(embed)
member.send(`You were quarantined in \`${message.guild.name}\`. Reason: ${reason} `).catch(error => {
message.channel.send(`❌ Can't send DM to ${member.user.tag}!`);
});
})
}
}
If I have made a mistake, please help me out
Sorry I don't speak English well
Try the below code out, I made notes along the way to explain as well as improved a small bit of code. I assume this is a collection of 2 separate files which is why they are separated. If they aren't 2 separate files, you do not need the top section, just the bottom.
const {
Client,
Intents,
MessageEmbed
} = require("discord.js");
const client = new Client({
allowedMentions: {
parse: ["roles", "users", "everyone"],
},
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES
]
});
const config = require("../config.json");
const {
MessageEmbed,
Permissions
} = require("discord.js");
module.exports = {
name: "quar",
run: async (client, message, args) => {
if (!message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return;
let role = message.guild.roles.cache.find(role => role.name === "Quarantined" || role.name === "Quarantine")
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = message.content.split(" ").slice(2).join(" ")
if (!reason) reason = "No reason given."
if (!role) return message.channel.send("❌ This server doesn't have a quarantine role!")
if (!member) return message.channel.send("❌ You didn't mention a member!")
if (member.roles.cache.has(role.id)) return message.channel.send(`❌ That user already quarantined!`)
member.roles.add(role)
.then(() => {
const embed = new MessageEmbed()
.setTitle(`✅ ${member.user.tag} was quarantined!`)
.setColor("RANDOM")
.setTimestamp()
.setFooter({
text: `Requested by ${message.author.username}`
})
// author and footer are now structured like this
// .setAuthor({
// name: 'Some name',
// icon_url: 'https://i.imgur.com/AfFp7pu.png',
// url: 'https://discord.js.org',
// })
// .setFooter({
// text: 'Some footer text here',
// icon_url: 'https://i.imgur.com/AfFp7pu.png',
// })
message.channel.send({
embeds: [embed]
}) //embeds must be sent as an object and this was the actual line that was causing the error.
member.send(`You were quarantined in \`${message.guild.name}\`. Reason: ${reason} `).catch(() => { // if error is not used, it is not required to be stated
message.channel.send(`❌ Can't send DM to ${member.user.tag}!`);
});
})
}
}

im trying to make a simple discord.js bot

i am trying to make it so as soon as you type: mememe it will react with: your nickname is now:
my current code is
const Discord = require("discord.js");
const client = new discord.client();
client.login(process.env.SECRET);
const embed = new Discord.MessageEmbed()
.setTitle("This is Embed Title")
.setDiscription("this is embed discription")
.setColor("RANDOM")
.SetFooter("This is Embed Footer");
const nicknames = ["dumbass", "idiot", "op", "man", "power", "docter"];
client.on("ready", () => {
client.user.setPresence({ activity: { name: "brave" }, status: "invisible" });
});
client.on("message", (message) => {
if (message.content === "ding") {
message.channel.send === "dong";
}
if (message.content === "embed") {
message.channel.send(embed);
}
});
if (message.content("mememe")) {
const index = Math.floor(Math.random() * nicknames.length);
message.channel.send(nicknames[index]);
}
but i dont know why it does not work it says as a error: Parsing error: Unexpected token
that is all and idk how to fix that
Edit : you guys were useless
I first want to say: Please fix your indents (I did it for you below here.
const Discord = require("discord.js")
const client = new Discord.Client()
client.login(process.env.SECRET)
// const embed = new Discord.MessageEmbed()
// .setTitle("This is Embed Title")
// .setDiscription("this is embed discription")
// .setColor("RANDOM")
// .SetFooter("This is Embed Footer");
const nicknames = ["dumbass", "idiot" , "op" , "man" , "power" , "docter"]
client.on("ready" , () => {
client.user.setPresence({ activity: { name: "brave"}, status: "invisible"})
})
client.on("message" , message => {
if(message.content === ("ding")) {
message.channel.send === ("dong")
}
if(message.content === ("embed")) {
message.channel.send(embed)
}
if(message.content === ("mememe")) {
const index = Math.floor(Math.random() * nicknames.length);
message.channel.send(nicknames[index])
}
})
The issue was you were calling the mememe command wrong. Above you used messega.content === "..."
In the mememe command you used message.content("mememe"). This does not work. Changes it (or copying the code above should fix the issue. Maybe an idea for you. You could add a feature where it changes the Users Nickname instead of sending a random one.

How to make my bot give send messages permissions to the specified role id , when prompted "=heist roleid"

I've made a discord bot and made a function in which it unlocks the channel for the members role which is appointed to everyone in my server. I want to make it so that it requires the id that is going to be unlocked after writing its id so basically =heist roleid.
I want this to unlock the channel only for the given role.
My current code:
const Discord = require("discord.js");
const client = new Discord.Client();
const prefix = ('=')
var numeral = require('numeral');
client.once('ready', () => {
console.log('Dank heists is now online');
client.user.setPresence({
activity: {
type:"PLAYING",
name: "discord.io/heists",
status: "available",
}
});
});
else if (message.content.startsWith(prefix +'heist' )) {
message.channel.createOverwrite("793930139737128997", {
SEND_MESSAGES: true
})
.then(channel => console.log(channel.permissionOverwrites.get(message.author.id)))
.catch(console.error);
const embed = new Discord.MessageEmbed()
.setTitle('HEIST HAS NOW STARTED!!!')
.setThumbnail('https://img2.pngio.com/unlocked-padlock-png-transparent-unlocked-padlockpng-images-lock-unlock-png-512_512.png')
.setColor('#1d35cf')
.setFooter('Manan, ')
.setDescription(" I HAVE UNLOCKED THIS CHANNEL SO PEOPLE CAN JOIN THE HEIST " )
message.channel.send(embed)
}
update and send the whole code all together if possible
I recommend you to learn JavaScript first and then learn the basics of Discord.js and Node.js.
Answer to your question :
else if (message.content.startsWith(prefix + "heist")) {
const roleT = message.content.replace(prefix + "heist", "").trim();
const role = message.guild.roles.cache
.filter((r) => r.name.toLowerCase() === roleT.toLowerCase())
.first();
if (!role) {
return message.channel.send("Please tag a role!");
}
message.channel
.createOverwrite(role.id, {
SEND_MESSAGES: true,
})
.then((channel) =>
console.log(channel.permissionOverwrites.get(message.author.id))
)
.catch(console.error);
const embed = new Discord.MessageEmbed()
.setTitle("HEIST HAS NOW STARTED!!!")
.setThumbnail(
"https://img2.pngio.com/unlocked-padlock-png-transparent-unlocked-padlockpng-images-lock-unlock-png-512_512.png"
)
.setColor("#1d35cf")
.setFooter("Manan, ")
.setDescription(
" I HAVE UNLOCKED THIS CHANNEL SO PEOPLE CAN JOIN THE HEIST "
);
message.channel.send(embed);
}

How can I change this script to kick user by user id?

I have this script for kicking users. How can I change that script so I can kick user by user id?
Script:
const discord = require('discord.js');
const client = new discord.Client;
const prefix = "$";
client.on('message', function(message) {
if (!message.content.startsWith(prefix)) { return }
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if(command === "kick") {
let member = message.mentions.members.first();
let reason = args.slice(1).join(" ");
if (member) { // add this
member.kick(reason);
client.channels.cache.get('737341022782357566').send("User <#" + member.id +
"> with id " + member.id + " has been kicked by <#" + message.author.id +
"> with reason " + reason)
} else {
message.reply("invalid parameters for $kick")
}
message.delete();
}
})
client.login('token');
You'll have to get the member by ID:
const Member = message.guild.members.cache.get('MemberId')
if (!Member) return console.log(`Invalid member.`);
And then kick them:
Member.kick("Reason").catch(error => {
console.log(`Couldn't kick ${Member.user.tag}.`);
})

Random Meme Command (discord.js v12)

I'm trying to make a 'random meme' command for my Discord Bot. I'm new to working with APIs, but I've tried my best.
The problem is, when I type the command, nothing happens. There are no errors, but the bot doesn't send anything in discord.
This is my code:
if (command === "meme")
async (client, message, args) => {
const subReddits = ["dankmeme", "meme", "me_irl"];
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
const img = await randomPuppy(random);
const embed = new Discord.MessageEmbed()
.setColor(16776960)
.setFooter("test")
.setImage(img)
.setTitle(`Random Meme requested by <#${message.author.tag}>`)
.setURL(`https://reddit.com/r/${random}`)
message.channel.send(embed);
}
Here Is One That Will Show Info About The Meme
if(command === "meme") {
const subReddits = ["dankmeme", "meme", "me_irl"];
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
try {
const { body } = await snekfetch
.get('https://www.reddit.com/r/${random}.json?sort=top&t=week')
.query({ limit: 800 });
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('It seems we are out of memes');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle(allowed[randomnumber].data.title)
.setDescription("Posted by: " + allowed[randomnumber].data.author)
.setImage(allowed[randomnumber].data.url)
.addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
.setFooter("r/" + random)
message.channel.send(embed)
} catch (err) {
return console.log(err);
}
}
Let Me Know If It Don't Work, But I Should
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 (command === "meme") {
async (client, message, args) =>
const subReddits = ["dankmeme", "meme", "me_irl"];
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
const img = await randomPuppy(random);
const embed = new Discord.MessageEmbed()
.setColor(16776960)
.setFooter("test")
.setImage(img)
.setTitle(`Random Meme requested by <#${message.author.tag}>`)
.setURL(`https://reddit.com/r/${random}`)
message.channel.send(embed);
}
});
This should work, not quite sure, haven't tested it. (You can put in a command handler your self)
if (command === "meme")
async (client, message, args) => {
const fetch = require('node-fetch');
let userAvatar = message.author.avatarURL({ format: "png", dynamic: true, size: 2048 }); // this is just the users icon, u can remove it if you want.
fetch(`https://meme-api.herokuapp.com/gimme`)
.then(res => res.json())
.then(async json => {
const embed = new MessageEmbed()
.setAuthor(`${json.title}`, `${userAvatar + "?size=2048"}`, `${json.postLink}`)
.setImage(`${json.url}`)
.setFooter(`👍${json.ups} | ${json.subreddit}`)
.setColor("RANDOM")
message.channel.send(embed).catch((error) => {
console.log("An error has occured on the \"meme\" command\n", error)
})
}
Here you go! I've tested this on my own command handler.

Resources