Hi I want to get the bot to send a direct/private message to new users that join the server. It is able to post a welcome message on a channel but it doesnt work when i does in in private messages.
const Discord = require('discord.js');
const config = require('./config.json');
const bot = new Discord.Client();
const prefix = '*';
bot.on('ready', () => {
console.log('Bot Démarré');
bot.user.setActivity('Chill \'N Code (*help)', { type: 'WATCHING' });
bot.user.setStatus('online');
})
bot.on('guildMemberAdd', member => {
console.log(member.user.username + " a rejoint le serveur");
const embed = new Discord.MessageEmbed()
.setTitle("<EARLY_SUPPORTER:840512953928515595> Bienvenue " + member.user.username + " !")
.setImage('https://i.imgur.com/Kbl451j.gif')
.setDescription("__**Voici quelques informations utiles :**__")
.addFields(
{ name: '\u200B', value: '\u200B' },
{ name: '<:channel:840513546416554045> **Règlement**', value: 'Nous T\'invitions à lire le [règlement](https://discord.com/channels/836947422122344448/836947422173200410/836962049484390449]', inline: false },
{ name: '<:add_reaction:840512848266657792> **Rôles**', value: 'Tu peux prendre tes rôles [ici](https://discord.com/channels/836947422122344448/836947422617141290/837022973830496286)', inline: false },
{ name: '<:moderation:840528469317517333> **Devenir Staff**', value: 'Tu peux devenir staff [ici](https://forms.gle/rGV26bZytcx5atG28)', inline: false },
{ name: '\u200B', value: '\u200B' },
{ name: 'Github', value: '[Github](https://github.com/chillncode)', inline: false },
{ name: 'Twitter', value: '[Twitter](https://twitter.com/ChillNCode1)', inline: false }
)
.setFooter('Chill \'N Code', 'https://cdn.discordapp.com/icons/836947422122344448/d27317d317a5b260d0365f6ca0da5455.png');
member.send(embed);
console.log("message envoyé");
})
Make sure you have the SERVER MEMBERS INTENT enabled in the Discord Developer Portal
Related
hi please i need some help the bot is giving an error which is yourid , productownerid , productname is not defined in last steps i tried many codes but no one worked for me if anyone can help me please and thank you
if(interaction.customId == 'evv'){
let yourid = interaction.fields.getTextInputValue('ask_1')
let productownerid = interaction.fields.getTextInputValue('ask_2')
let productname = interaction.fields.getTextInputValue('ask_3')
let evalmsg = interaction.fields.getTextInputValue('ask_4')
const exampleEmbed = new MessageEmbed()
.setColor("RANDOM")
.setFields(
{ name: '**Buyer-Name**', value: `<#${yourid}>`}
{ name: '**Owner Of The Product**', value:`**<#${productownerid}>**`}
{ name: '**Product**', value:`**${productname}**`}
{ name: '**Message**', value: `**${evalmsg}**`}
)
.setFooter(`Requested By ${interaction.user.tag} , ${new Date()}`)
let button25 = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('1')
.setLabel("تقييم")
.setStyle('PRIMARY')
.setEmoji("💖")
)
await interaction.guild.channels.cache.get("1048414164932108289").send({embeds: [exampleEmbed],components:[button25]})
}
the error is from here :
if (interaction.customId == '1'){
const exampleEmbed2 = new MessageEmbed()
.setColor("RANDOM")
.setFields(
{ name: '**Buyer-Name**', value: `<#${yourid}>`}
{ name: '**Owner Of The Product**', value:`**<#${productownerid}>**`}
{ name: '**Product**', value:`**${productname}**`}
{ name: '**Message**', value: `**${evalmsg}**`}
{ name: '**Evaluation**', value: `**💖**`}
)
.setFooter(`Requested By ${interaction.user.tag} , ${new Date()}`)
interaction.guild.channels.cache.get("1048414164932108289").send({embeds: [exampleEmbed2],components:[]})
}
})```
Instead of using <#${yourid}>, you can use userMention(yourid) but i don't think it's the problem.
I think the probleme is the .setFooter for the date you don't have to do ${new Date()} there is a command for this : .setTimestamp().
Or another problem you can't put "RANDOM" in .setColor
And I use new EmbedBuilder() instead of messageEmbed()
You also have to put "," at the end of a field like this :
.setFields(
{ name: '**Buyer-Name**', value: `<#${yourid}>`},
{ name: '**Owner Of The Product**', value:`**<#${productownerid}>**`},
{ name: '**Product**', value:`**${productname}**`},
{ name: '**Message**', value: `**${evalmsg}**`},
{ name: '**Evaluation**', value: `**💖**`},
)
You also have to set a Title with .setTitle('title')
The last error i saw is for search a channel I use interaction.guild.channels.fetch('id')
So i propose you this correction :
if (interaction.customId == '1'){
const exampleEmbed2 = new EmbedBuilder()
.setTitle('title')
.setColor(15548997)
.addFields(
{ name: '**Buyer-Name**', value: userMention(yourid)},
{ name: '**Owner Of The Product**', value: '**' + userMention(productownerid) + '**'},
{ name: '**Product**', value:`**${productname}**`},
{ name: '**Message**', value: `**${evalmsg}**`},
{ name: '**Evaluation**', value: `**💖**`},
)
.setFooter(`Requested By ${interaction.user.tag}`)
.setTimestamp()
interaction.guild.channels.fetch("1048414164932108289").send({embeds: [exampleEmbed2]})
}
So this may just be me being stupid and forgetting a semicolon or something, but I can't seem to resolve this. For my ticket command, I make it so when someone uses the command /ticketsetup and it saves the data of the inputted channels as ID's to then be referenced later. But for some reason, one of them just saves a completely random ID that isn't related to the inputted channel (Transcript)
const {MessageEmbed, CommandInteraction, MessageActionRow, MessageButton} = require('discord.js')
const DB = require('../../Structures/Schemas/TicketSetup')
module.exports = {
name: "ticketsetup",
usage: "/ticketsetup (Admin only)",
description: "Setup your ticketing message.",
permission: "ADMINISTRATOR",
options: [
{
name: "channel",
description: "Select the ticket creation channel.",
required: true,
type: "CHANNEL",
channelTypes: ["GUILD_TEXT"]
},
{
name: "category",
description: "Select the ticket channel's category.",
required: true,
type: "CHANNEL",
channelTypes: ["GUILD_CATEGORY"]
},
{
name: "transcripts",
description: "Select the transcripts channel.",
required: true,
type: "CHANNEL",
channelTypes: ["GUILD_TEXT"]
},
{
name: "handlers",
description: "Select the ticket handler's role.",
required: true,
type: "ROLE"
},
{
name: "description",
description: "Set the description of the ticket creation channel.",
required: true,
type: "STRING"
}
],
/**
*
* #param {CommandInteraction} interaction
*/
async execute(interaction) {
const {guild, options} = interaction
try {
const Channel = options.getChannel("channel")
const Category = options.getChannel("category")
const Transcripts = options.getChannel("transcripts")
const Handlers = options.getRole("handlers")
const Description = options.getString("description")
await DB.findOneAndUpdate({GuildID: guild.id},
{
ChannelID: Channel.id,
Category: Category.id,
Transcripts: Transcripts.id,
Handlers: Handlers.id,
Everyone: guild.id,
Description: Description,
},
{
new: true,
upsert: true
}
);
const Embed = new MessageEmbed().setAuthor({
name: guild.name + " | Ticketing System",
iconURL: guild.iconURL({dynamic: true})
})
.setDescription(Description)
.setColor("#36393f")
const Buttons = new MessageActionRow()
Buttons.addComponents(
new MessageButton()
.setCustomId("ticket")
.setLabel("Create Ticket!")
.setStyle("PRIMARY")
.setEmoji("🎫")
)
await guild.channels.cache.get(Channel.id).send({embeds: [Embed], components: [Buttons]})
interaction.reply({content: "Done", ephemeral: true})
} catch (err) {
const ErrEmbed = new MessageEmbed().setColor("RED")
.setDescription(`\`\`\`${err}\`\`\``)
interaction.reply({embeds: [ErrEmbed]})
}
}
}
Schema Model:
const {model, Schema} = require('mongoose')
module.exports = model("TicketSetup", new Schema({
GuildID: String,
Channel: String,
Category: String,
Transcripts: String,
Handlers: String,
Everyone: String,
Description: String,
}))
exports.run = async (client, message, args) => {
let data = await cs.leaderboard(message.guild.id);
if (data.length < 1) return message.reply("Nobody's in leaderboard yet.");
const msg = new Discord.MessageEmbed();
let pos = 0;
// This is to get First 10 Users )
data.slice(0, 10).map(e => {
if (!client.users.cache.get(e.userID)) return;
pos++
msg.setColor('#0099ff')
msg.setTitle('Leaderboard')
msg.setAuthor({ name: 'Arkbuddies UK', iconURL: 'https://i.imgur.com/yHgaVv2.png', url: 'https://discord.js.org' })
msg.setThumbnail('https://i.imgur.com/yHgaVv2.png')
msg.addFields(
{ name: `${pos}\u200B\n`, value: `**${client.users.cache.get(e.userID).username}**`, inline: true },
{ name: `Wallet:`, value: `**${e.wallet}** <:Wishbone:939942552809902150>'s`, inline: true },
{ name: `Bank:`, value: `**${e.bank}** <:Wishbone:939942552809902150>'s`, inline: true},
)
msg.setTimestamp()
msg.setFooter({ text: 'Arkbuddies UK', iconURL: 'https://i.imgur.com/yHgaVv2.png' });
});
message.reply({
embeds: [msg]
}).catch();
}
exports.help = {
name: "leaderboard",
data: {
name: 'leaderboard',
description: "show's guild leaderboard.",
options: []
}
}
exports.conf = {
aliases: ["lb"],
cooldown: 5
}
I have an issue with discord.js slash commands.
As you can see in my code I am setting the name to "Name" and "Age" so I don't understand what the issues are.
This is my error:
error: (node:16004) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
options[0].name: Command name is invalid
And this is my code:
const Discord = require('discord.js');
require("dotenv").config();
const client = new Discord.Client();
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const getApp = (guildid) => {
const app = client.api.applications(client.user.id);
if(guildid){
app.guilds(guildid);
}
return app;
}
await getApp("842486032842358784").commands.post({
data: {
name: 'embed',
description: 'Displays embed',
options: [
{
name: 'Name',
description: 'Your Name',
required: true,
type: 3
},
{
name: 'Age',
description: 'Your Age',
required: false,
type: 4
}
]
},
})
client.ws.on('INTERACTION_CREATE', async(interaction) => {
const command = interaction.data.name.toLowerCase();
const { name, options } = interaction.data;
console.log(options);
if(command === "embed"){
reply(interaction, 'hi');
}
})
const reply = (interaction, response) => {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: response,
}
}
})
}
});
client.login(process.env.TOKEN);
The option names should be all lowercased, in your case, substitute "Name" with "name" and "Age" with "age". That should work. The code is below:
const Discord = require('discord.js');
require("dotenv").config();
const client = new Discord.Client();
client.on('ready', async() => {
console.log(`Logged in as ${client.user.tag}!`);
const getApp = (guildid) => {
const app = client.api.applications(client.user.id);
if (guildid) {
app.guilds(guildid);
}
return app;
}
await getApp("842486032842358784").commands.post({
data: {
name: 'embed',
description: 'Displays embed',
options: [{
name: 'name',
description: 'Your Name',
required: true,
type: 3
},
{
name: 'age',
description: 'Your Age',
required: false,
type: 4
}
]
},
})
client.ws.on('INTERACTION_CREATE', async(interaction) => {
const command = interaction.data.name.toLowerCase();
const {
name,
options
} = interaction.data;
console.log(options);
if (command === "embed") {
reply(interaction, 'hi');
}
})
const reply = (interaction, response) => {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: response,
}
}
})
}
});
client.login(process.env.TOKEN);
I want to edit the author of an embed sent by my bot.
The message is sent by this code :
task_chan.send('', {
embed: {
color: task_colors[0x808080],
title: 'Tache n°1',
thumbnail: {
url: 'https://...'
},
author: {
name: 'Tache à prendre',
icon_url: 'https://zupimages.net/up/20/12/xqsf.jpg'
},
fields:[{
name: "Tache à faire :",
value: "...",
},{
name: 'Avancement de la tache :',
value: 'Non commencée'
}]
}
})
To edit the message I've tried :
taken.embeds[0].author.icon_url = util.avatarURL
taken.embeds[0].author.name = util.username
taken.edit(new Discord.RichEmbed(taken.embeds[0]));
taken contain the message to edit and util an user.
And it only change the name…
I don't understand why but author.icon_url is undefined between these two code samples.
I hope you can help me :)
method channel.send return a promise, so you can use .then(msg=> to get a message object.
let testEmbed = {
color: task_colors[0x808080],
title: 'Tache n°1',
thumbnail: {
url: 'https://...'
},
author: {
name: 'Tache à prendre',
icon_url: 'https://zupimages.net/up/20/12/xqsf.jpg'
},
fields:[{
name: "Tache à faire :",
value: "...",
},{
name: 'Avancement de la tache :',
value: 'Non commencée'
}]
}
}
task_chan.send({embed:testEmbed}).then(msg => {
testEmbed.name = 'LOL'
testEmbed.iconURL = 'SOMEURL'
msg.edit({embed:testEmbed})
})
I would recommend that you use the built-in methods for creating embeds, in my opinion it is more convenient.