Mentioning roles in slash command reply discors.js BOT - discord

I am making a Discord bot using discord js v13.2.0, and I want to reply to an interaction with a mention to an role, but when the interaction is "sent", it not ping the role.
I am just a beginner in code so maybe I do something wrong, I tried looking on the internet but I found nothing.
async execute(interaction, client) {
interaction.reply({
"content": "This is the role mention : <#&roleid>"
})
},
What I have

To allow mentions in interaction you can use allowedMentions:
interaction.reply({
allowedMentions: {roles: ['YOUR_ROLE_ID']},
content: "This is the role mention: <#&roleid>"
})

Related

POST Error when using Discord Webhook in Dev Console on discord.com

I am using a piece of JS I saw in an online tutorial to send a webhook to a discord server I own. When I run the code from localhost on my computer it sends the webhook no problem. However, when I paste the same code into the console on a tab with discord open, the code does not run and I receive a POST error 400. It was working a month ago, What am I doing wrong?
Please note the webhook url shown is not real. Below is the JS I am using:
function sendMessage() {
const request = new XMLHttpRequest();
request.open("POST", "https://discordapp.com/api/webhooks/676118118082281513/ZS5YcWhurzokBrKX9NgexqtxrJA5Pu2Bo4i7_JsIxC-JIbPBVhSZkcVVukGOro52rnQA");
request.setRequestHeader('Content-type', 'application/json');
const params = {
username: "My Webhook Name",
avatar_url: "",
content: "The message to send"
}
request.send(JSON.stringify(params));
}
sendMessage()

My discord bot is not pinging everyone. It is sending the #everyone message, but its not pinging anybody. (Discord.js V13)

My discord bot is not mentioning anybody after sending #everyone. Like, it is sending the #everyone message. But it doesn't ping anybody. I have my bot's permissions with pinging everyone enabled. But it still doesn't work.
Here's the code:
const discord = require('discord.js');
module.exports = {
info: {
name: "announcement",
description: "Announcement!",
},
name: "announcement",
description: "Announcement!",
async execute(Discord, client, interaction){
await interaction.reply(`#everyone`);
}
}
I expect the bot to ping everyone, and it doesn't. That's the issue.
Use allowedMentions:{parse:["everyone"]} as option when sending a reply or message. For example: interaction.reply({content:'#everyone',allowedMentions:{parse:["everyone"]}})
You can change your client constructor to be as follows:
const client = new Discord.Client({
intents: 32767,
allowedMentions: {parse: ["roles", "users"], repliedUser: true}//this enables #everyone mention (parse users)
});

How can I DM the user an embed before he is kicked (discord.js)

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!"
}] })

Discord bot not dming, while having all of the intents on

I have a discord bot that is supposed to DM the user anytime they have a moderator action against them. (Getting muted, etc.)
DiscordAPIError: Missing Permissions
I have all of the intents on for the bot and it is only in 2 servers.
Picture Here
This is the code I use to DM, it is in typescript but I basicly use discord.JS documentation and that while writing it due to its simularities.
try {
await user.createDM()
await user.send(`You have been muted for ${reason!}! It will last ${time!} minutes!`)
} catch (error) {
await interaction.reply({
content: `The player was not DMed!`,
ephemeral: true,
});
}
I just relised that I forgot to remove part of the script not shown from the orginial script it was copied from.

Send DMed files and links to channel in server

Okay. This might be a strange question, but I need help as I could not find anything online. I have a discord bot and server that is hosts a competition, and users submit their submissions by Direct Messaging me a link or file of their submission. I would like to change this to them DMing the bot instead, and the bot posting the links and files in a certain channel in the server. I have absolutely no clue how to achieve this as I am kind of a novice when it comes to this sort of thing. Please comment if I need to change my wording or need to clarify anything!
Replace channel id with the actual id of the channel that you want to send the submissions to.
For Discord.js v12/v13 (the latest version):
client.on('message', ({attachments, author, content, guild}) => {
// only do this for DMs
if (!guild) {
// this will simply send all the attachments, if there are any, or the message content
// you might also want to check that the content is a link as well
const submission = attachments.size
? {files: [...attachments.values()], content: `${author}`}
: {content: `${content}\n${author}`}
client.channels.cache.get('channel id').send(submission)
}
})
For Discord.js v11 replace
client.channels.cache.get('channel id').send(submission)
with
client.channels.get('channel id').send(submission)
In the message event, you can check if the message is in a dm channel then you can take the message content and send it to a specific channel as an embed.
Your solution would be:
client.on('message', (message) => {
if (message.channel.type === 'dm') {
const channel = client.guilds.cache.get("GUILD_ID").channels.cache.get("CHANNEL_ID");
const embed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, message.author.avatarURL())
.setColor('RANDOM')
.setDescription(message.content)
channel.send(embed);
if (message.attachments.array().length) {
message.attachments.forEach((attachment) => channel.send({ files: [ attachment ] }))
}
}
})

Resources