My code does not return an error but when I call it on discord, it does not responding.
import { SlashCommandBuilder, EmbedBuilder, CommandInteraction } from "discord.js";
import { SlashCommand } from "../types";
export const command: SlashCommand = {
name: "dé",
data: new SlashCommandBuilder().setName("dé").setDescription("DUEL"),
execute: async (interaction) => {
const liste = [
"`1, tu as fait une réussite critique`",
"`2, tu as fait une réussite moyenne`",
"`3, tu as fait une réussite moyenne`",
"`4, tu as fait une petite réussite`",
"`5, tu as fait un petit échec`",
"`6, tu as fait un echec critique`",
"`7, quelque chose de drôle va arriver`",
"`8, ça provoque l'effet d'un autre sort`",
];
await interaction.reply({
embeds: [new EmbedBuilder().setDescription(liste[Math.floor(Math.random() * liste.length)])],
});
},
};
I would like to make an slashcommand that answers one of these eight answers at random.
I copied your code and checked myself, it works. So the problem is something else, didn't you forget to configure intents? Because it depends on whether the bot can write to the guild.
For example, you can set up the client in this way:
export const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageTyping
]})
You also need to go to https://discord.com/developers/applications/. There, click on the "Bot" tab and turn on all the checkboxes on Privileged Gateway Intents
P.S. Below I'm just proving that the code works. execute is a slash command
Related
I would like to make a commander (cmd slash) to activate maintenance on a remote server. Most of the order is done and functional. But when I want to put the number of minutes via a .addNumberOption, I get the error
Option "minutes" is of type: 10; expected 3.
data: new SlashCommandBuilder()
.setName('maintenancemc-staff')
.setDescription('Active ou désactive le mode maintenance du serveur Minecraft')
.addStringOption((option) =>
option
.setName('raison')
.setDescription('Raison du changement de statut')
.setRequired(true)
)
.addNumberOption((option) =>
option
.setName('minutes')
.setDescription("Décompte d'activation du mode maintenance en minute")
.setRequired(true)
),
async execute(interaction, client) {
await interaction.deferReply({ fetchReply: true, ephemeral: true });
const { options } = interaction;
const raison = options.getString("raison");
const timer = options.getString("minutes");
...
Thank you in advance for your help! 🦊
If you use addNumberOption, instead of options.getString("minutes"), you need to use options.getNumber("minutes").
i have a embed on my ready.js that sends it to a channel, and its giving me this error
ValidationError: Expected the value to be an object, but received string instead
at ObjectValidator.handle (/root/ZyruzBot/node_modules/#sapphire/shapeshift/dist/index.js:1161:25)
at ObjectValidator.parse (/root/ZyruzBot/node_modules/#sapphire/shapeshift/dist/index.js:113:88)
at EmbedBuilder.setAuthor (/root/ZyruzBot/node_modules/discord.js/node_modules/#discordjs/builders/dist/messages/embed/Embed.cjs:42:37)
at sendTicketMSG (/root/ZyruzBot/events/ready.js:13:10)
at Timeout._onTimeout (/root/ZyruzBot/events/ready.js:86:7)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
validator: 's.object(T)',
given: '🎫 Cria um ticket aqui'
}
Heres the embed and the start of the code:
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: 'ready',
async execute(client) {
console.log('Bot Online!')
console.log('Bot Dev Chain');
const oniChan = client.channels.cache.get(client.config.ticketChannel)
function sendTicketMSG() {
const embed = new EmbedBuilder()
.setColor('ff0000')
.setAuthor('🎫 Cria um ticket aqui', client.user.avatarURL())
.setDescription('Aqui pode abrir um ticket para obter\n\n **__<:SupportTeam:1013602711683473499> Suporte\n <:Servers:1013601908105171014> Adquirir a sua vps\n <a:developer_bot:1013602040745824336> Adquirir o seu bot de discord\n <a:partnership:1013602912162828308> Fazer uma Parceria__**')
.setFooter(client.config.footerText, client.user.avatarURL())
const row = new client.discord.MessageActionRow()
.addComponents(
new client.discord.MessageButton()
.setCustomId('open-ticket')
.setLabel('Cria um ticket aqui')
.setEmoji('🎫')
.setStyle('PRIMARY'),
);
oniChan.send({
embeds: [embed],
components: [row]
})
}
Idk whats generating this error, if you guys know please let me know
Your error lies in the .setAuthor() Method. It seems, that you use a newer version of discord.js in which this method requests an Object with the information.
In this link is another example using an object, maybe this will resolve your issue.
EmbedBuilder
I want to make a Setup Command for my Bot, that I can use to set up channels for the bot e.g. a welcome channel. For this, I used a JSON file.
Code
collector.on('collect', async (i) => {
if (i.customId === 'modchannelbutton') {
const ModChannelSetEmbed = new MessageEmbed()
.setTitle('<:vsl_settings:991655211179442216> | **__SERVER SETUP__**')
.addField(
'» Stand',
setupconfig[interaction.guild.id].modlog === 'nochannel'
? '<:m_notdone:991657968296808478> Du hast noch kein Moderator Log gesetzt'
: `<:m_done:991657855549710376> Dein aktueller Moderator Log ist: <#${
setupconfig[interaction.guild.id].modlog
}>`,
)
.setDescription(
'> Du hast 1 Minute Zeit um einen neuen Moderator Log zu setzen, schreib dafür einfach nur den #Channel in diesem Channel',
)
.setColor('#0c06b6');
row.components[0].setDisabled(true);
await i.update({ embeds: [ModChannelSetEmbed], components: [] });
// … Here I need the Message Collector for the Channel …
}
});
I want to make a collector that collected if the message next to the button is clicked in a channel. But all my tries don't reply.
That means:
Slash Command use —> Button Click —> Channel send
The Collector should control if the message next to the button click is a channel.
When I try to execute this code (for a warn system in Discord.JS), I have this error
ReferenceError: member is not defined
name: 'warn',
description: 'Pour warn un membre',
execute(message, args, Client){
if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Tu n'as pas les permissions de warn un membre");
if(message.channel.type == "dm") return;
let mention = message.mentions.members.first();
const reason = args.slice(1).join(' ')
if(mention == undefined){
message.reply("Membre non-menntionné ou mal mentionné");
}
else {
if (!reason) return message.channel.send("Veuillez indiquer une raison")
if (!Client.warn.warns[member.id]) Client.warn.warns[member.id] = []
Client.warn.warns[member.id].unshift({
reason,
date: Date.now(),
mod: message.author.id
})
fs.writeFileSync('./commands/bdd/warns.js', JSON.stringify[Client.warn])
message.channel.send(`${member} a été warn pour ${reason}`)
}
},
};
Can you help me ?
Thanks
You defined your member as mention, in the line:
let mention = message.mentions.members.first();, however, you use member in for example if (!Client.warn.warns[member.id]). If you change all the member which should be mention to mention, it's fixed :)
Hello I made a ban command, but on the line: I put:
which corresponds to the first mention of the message.
Except that the mention can be anywhere, so I'm looking for how to make the bot detect that the mention is at the beginning or not.
Any help is appreciated.
Thank you for taking the time to read this and I wish you a good day.
module.exports.run = async(client, message, args) => {
const Discord = require("discord.js");
const Breason = message.content.slice(22);
let target = message.mentions.users.first();
if(!message.guild.me.permissionsIn(message.channel.id).has("SEND_MESSAGES")) return;
if(!message.guild.me.permissionsIn(message.channel.id).has("EMBED_LINKS")) return;
if(!message.guild.member(client.user).hasPermission("BAN_MEMBERS")) return message.channel.send("Je n'ai pas la permsission de ban ce membre.")
if(!message.guild.member(message.author).hasPermission("BAN_MEMBERS")) return message.channel.send("Vous n'avez pas la permission de ban")
if(bUser === message.author.id) return message.channel.send("Vous ne pouvez pas vous auto-ban.")
if(!bUser) return message.channel.send("Veuillez mentionnez un utilisateur à bannir.")
if(!Breason) return message.channel.send("Ho ! Il manque une raison, serait ce un abus de privilèges ?:thinkinghard: ")
message.guild.members.ban(bUser, {reason: Breason})
const embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("Un membre à été banni !")
.addField("Membre banni :", bUser.tag, true)
.addField("Banni par:", message.author.tag, true)
.addField("Pour la raison:", Breason, true)
.setFooter("Une nouvelle personne a été banni !")
.setTimestamp()
message.channel.send(embed)
bUser.send(embed)
};
module.exports.help = {
name: "ban",
aliases: ["Bane", "banne"],
description: "Ban l'utilisateur mentionner.",
usage: "ban <user.mention> <raison>"
};
If my explanations are not clear, let me know and I will be happy to correct.
Assuming that args is an array of arguments from message.content (separated by whitespace),
let target = args[0].includes(message.mentions.users.first().id) ? message.mentions.users.first() : null;