I am not 100% sure on how to do this or if its possible but is there a way that a user could do
#command issue here
and send the issue towards a specific channel or admin?
So its basically like a way to report issues towards admins of the bot
I would appreciate the help and thanks in advance
module.exports = {
name: "reportissue",
description: "Report an issue you are experiencing with the bot",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: ["ADMINISTRATOR"],
},
aliases: ["report", "issue"],
run: async (client, message, args, { GuildDB }) => {
// I have removed this since its not the correct usage
// message.channel.send("issue");
};
}
}
Yes, this would work
const query = args.join (" ")
if(!query) return message.channel.send("Please specify the bug you want to report")
const reportEmbed = new MessageEmbed()
.setTitle('Bug!')
.addField('Author', message.author.toString(), true)
.addField('Report', query)
.addField('Guild', message.guild.name, true)
.setThumbnail(message.author.displayAvatarURL({ dynamic: true }))
.setTimestamp()
message.channel.send('We are extremely sorry for this issue. Your report has successfully been submitted and will be looked into. \n Regards, AuraBot Team')
client.channels.cache.get('id').send(reportEmbed);
Related
I'm trying to make a blacklist command, and how do I make it so it sends an embed instead of normal message.
(Also, I'm new to discord.js)
Here's my script:
module.exports = {
data: new SlashCommandBuilder()
.setName('blacklist')
.setDescription('Blacklist someone from the server')
.addUserOption((option) => option.setName('member')
.setDescription('Who are you blacklisting?')),
async execute(interaction) {
await interaction.deferReply();
const member = interaction.options.getMember('member');
if (!interaction.member.roles.cache.some(r => r.name === "Blacklist perms")) {
return interaction.editReply({ content: 'You do not have permission to use this command!' });
}
member.send("You have been blacklisted!")
member.kick().catch(err => {
interaction.editReply({ content: `I do not have enough permissions to do that.`})
})
await interaction.editReply({ content: `${member} has been succesfully blacklisted!` });
},
};```
Since your function is already async, simply await sending the message before you call kick.
await member.send("You have been blacklisted!")
member.kick().catch(err => {
interaction.editReply({ content: 'I do not have enough permissions to do that.'})
})
You might also wanna catch() on the send method because users can have DMs from server members disabled or blocked your bot.
You also might consider banning the user instead, because this system would fail if your bot ever happens to go offline when a blacklisted user tries to join. Additionally, depending on how fast your bot reacts, the user may still have time to spam in channels or do something harmful before your bot is able to kick them.
To send an embed either use an EmbedBuilder or a plain JavaScript object with the correct embed structure.
Example:
member.send({ embeds:[{
title: "Title",
description: "Hello World!"
}] })
I tried to make a bot that can kick users and I have a probem with checking if user has a permision to do so. I have aready searched for it trough the whole internet and everywere it was sad to use .has but it doesn't seems to work, console always returns error: Cannot read properties of undefined (reading 'has').
Here's my code:
const { SlashCommandBuilder } = require("#discordjs/builders");
const { Permissions } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName("kick")
.setDescription("Kicks someone")
.addUserOption(option =>
option
.setName("user")
.setDescription("Select the user")
.setRequired(true)),
async execute(interaction){
const user = interaction.options.getUser("user");
const userId = interaction.guild.members.cache.get(user.id);
if(!interaction.user.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) return interaction.reply("You dont have perrmisions to kick KEKW!");
if(!interaction.guild.permissions.me.has(Permissions.FLAGS.KICK_MEMBERS)) return interaction.reply("I dont have perrmisions to kick KEKW!");
if(userId == interaction.user.id) return interaction.reply(
{
content: "You cant kick yourself bro!",
ephemeral: true
});
interaction.reply({
content: `You have succesfuly kicked user: ${user}!`,
ephemeral: true
});
userId.kick();
}
}
Here's the error:
https://ibb.co/86xPdJv
interaction.user is a User object, so methods only available to GuildMember, like permissions.has cannot be applied to the interaction.user. Change it to interaction.member will solve the problem. It's also a good idea to read more about User and GuildMember objects and their differences in the discord.js documentation and guide. I've linked these below:
discord.js documentation pages on topic:
https://discord.js.org/#/docs/discord.js/stable/class/User -User
https://discord.js.org/#/docs/discord.js/stable/class/GuildMember -GuildMember
discord.js guide on topic:
https://discordjs.guide/popular-topics/faq.html#what-is-the-difference-between-a-user-and-a-guildmember
I want it so when it joins a new server instead of console logging new server joined it would send a embed to the bots support server
You need to save the id from the specific channel you want to send it in somewhere and instead of console logging it you have to do something like client.channels.cache.get(channelID).send(embed)
You really need to specify your questions more, show what you are working on. StackOverflow is not coding service, but I'm feeling generous. Just remember this is example of the code that might not work for you, because I have no idea how your bot is set up.
const { MessageEmbed } = require("discord.js");
client.on("guildCreate", newguild => {
const embed = new MessageEmbed()
.setTitle(`NEW SERVER`)
.addFields(
{name: `SERVER`, value: newguild.name, inline: true},
{name: `ID`, value: newguild.id, inline: true}
);
let supportserver = client.guilds.cache.find(g => g.id === 'support-server-id-here');
supportserver.channels.cache.find(ch => ch.id === 'channel-id-here').send({embeds: [embed]});
});
Hopefully this will get you on the right track.
So I have this command that shows the riches users in a server this command worked yesterday however recently it has stopped working.
const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");
const { prefix } = require("../../botconfig.json");
const db = require('quick.db')
let bal = require('../../database/balance');
let rep = require('../../database/rep');
let work = require('../../database/works');
module.exports = {
config:{
name: "rich",
aliases: ["r"],
category: "currency",
description: "Tells who is rich",
usage: ""
},
run: async (client, message, args) => {
// Get all members of the server before doing anything
message.guild.members.fetch().then(guildMembers => {
let board = [];
for (let key of Object.keys(bal)) {
// Checks if the collection of GuildMembers contains the key.
if (guildMembers.has(key)) {
let value = Object.assign({user: guildMembers.get(key).user}, bal[key]);
board.push(value);
}
}
const emojis = [':first_place:', ':second_place:', ':third_place:', ':small_blue_diamond:', ':small_blue_diamond:']
board = board.sort((a,b) => b.balance-a.balance).splice(0, 5);
let top = board.map((x, i) => `${emojis[i]} **${x.balance.toLocaleString()}** - ${x.user.tag}`).join('\n');
let embed = new MessageEmbed()
.setColor("RANDOM")
.addField(`Richest users in **${message.guild.name}**`, `${top}`)
.setFooter('Switch Version 1.1');
return message.channel.send(embed);
}).catch(console.error)
}
}
The error code when the !rich command is used is as follows:
Guild_Members_Timeout: Members didn't arrive in time
I don't know if this is an issue within the bot or if it is an issue with discord.
Okay I have found the answer to my own problem it seems I needed to add intents to my discord bot to fetch the members.
All I did was add this line of code and it worked.
const intents = new Intents([
Intents.NON_PRIVILEGED, // include all non-privileged intents, would be better to specify which ones you actually need
"GUILD_MEMBERS", // lets you request guild members (i.e. fixes the issue)
]);
const client = new Client({ ws: { intents } });
None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out? . In this post it is explained in great detail and that helped me out a lot.TLDR:go to discord developer portal on your particular application ,go to bot , on bot permissions tick whatever is needed and copy the number.Then use this number as a constructor parameter for new Discord.Intents('insert the number here').This worked for me.
Basically, I need to grab the permissions from the current text channel the user is in. I have already got the channel name, if I need to get the ID that should be pretty easy to do.
const Discord = require("discord.js");
module.exports.run = async (client, message, args) => {
let currentChannel = message.channel.name;
let category = message.channel.parent;;
message.guild.createChannel(currentChannel).then(mchannel => {
mchannel.setParent(category).then(() => {
message.channel.delete();
});
});
}
module.exports.help = {
name: "a.cleanchannel"
}
// Need the channel permissions to overwrite the new channel's permissions with the old ones
The expected results are that the channel should have the same permissions as the old one.
To answer your question directly, you can use GuildChannel#permissionOverwrites to create the new channel with the same permissions as the old one. For example...
message.guild.createChannel(message.channel.name, {
type: 'text',
permissionOverwrites: message.channel.permissionOverwrites
});
However, it looks like you're trying to clone a channel. To help make that easier, there's a method built into Discord.js for it - GuildChannel#clone(). You can use it like so...
message.channel.clone(undefined, true, true) // Same name, same permissions, same topic
.then(async clone => {
await clone.setParent(message.channel.parent);
await clone.setPosition(message.channel.position);
await message.channel.delete();
console.log(`Cloned #${message.channel.name}`);
})
.catch(console.error);