const { MessageEmbed, WebhookClient, GuildMember} = require('discord.js');
module.exports = {
name : 'guildMemberAdd',
/**
*
* #param {GuildMember} member
*/
async execute(member) {
const {guild, user} = member;
const welcomer = new WebhookClient({
id : '958046742446759936',
token: '3X9d1gJT8rLCyV-WFkorfkpU5Tl9iF8IXWMz3BOfuR7GQ1Sf5V5OD1HwWxRHRLf97tK0'
});
const welcome = new MessageEmbed()
.setColor('AQUA')
.setAuthor({name: user.tag,iconURL: user.avatarURL({dynamic:true})})
.setThumbnail(user.avatarURL)
.setDescription(`Welcome ${member} to the **${guild.name}**!\nAccount Created: <t:${parseInt(user.createdTimestamp/1000)}:R>\nLatest Member Count: **${guild.memberCount}**`)
.setFooter({
text: user.tag,
iconURL: user.avatarURL()
})
welcomer.send({embeds:[welcome]})
let welcomeRole = guild.roles.cache.find(role => role.id === '954841166933811210');
console.log(`${user.tag} has joined the server`)
member.roles.add(welcomeRole);
}
}
I am trying to do create an embed but it is not loading the thumbnail please help me to do it as I am very upset
it did not even give my photo in the embed what is the problem behind it is this is in code or from discord
use user.displayAvatarURL() instead of user.avatarURL()
Related
I'm new with these bot, and I'm trying to mention user with an embed like picture. I've tried this but only sending messages and mention user, not the picture.
const { MessageAttachment } = require("discord.js");
module.exports = {
name: 'karungin',
description: 'this is karungin command',
execute(message, args){
mention = message.mentions.users.first();
const attach = new MessageAttachment("karungin.jpg");
message.channel.send(`Hello <#${mention.id}>`, {files: [attach]});
}
};
What should I do ?
Use an option object to send your message:
const { MessageAttachment } = require("discord.js");
module.exports = {
name: 'karungin',
description: 'this is karungin command',
execute(message, args){
mention = message.mentions.users.first();
const attach = new MessageAttachment("karungin.jpg");
message.channel.send({content: `Hello <#${mention.id}>`, files: [attach]});
}
};
When specifying a string, only the content is taken into account.
Im trying to make a shifumi game in discord.js to train my skills.
So I created my command to create a game and design our mate.
const { MessageEmbed, MessageActionRow, MessageButton, Permissions} = require('discord.js');
const { SlashCommandBuilder } = require('#discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('shifumi')
.setDescription('Play to shifumi with another user')
.addUserOption(option =>
option.setName('player')
.setDescription('The player you want to play with')
.setRequired(true)),
async execute(interaction) {
exports.userMain = interaction.user;
exports.userPlayer = interaction.options.getUser('player');
const shifumiEmbed = new MessageEmbed()
.setColor('#00B9FF')
.setTitle("Shifumi")
.setDescription('Indiquez la finalisation de votre exercice en cliquant sur le bouton ci-dessous.');
const rockButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('rock-button')
.setLabel('Pierre\ \ ')
.setStyle('PRIMARY')
.setEmoji('🌑'),
);
const leafButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('leaf-button')
.setLabel('Feuille\ \ ')
.setStyle('PRIMARY')
.setEmoji('🍃'),
);
const scissorsButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('scissors-button')
.setLabel('Ciseaux')
.setStyle('PRIMARY')
.setEmoji('✂️'),
);
interaction.channel.send({ embeds: [shifumiEmbed], components: [rockButton, leafButton, scissorsButton]});
return interaction.reply({ content: `Game started !`, ephemeral: true });
},
};
And I need to use these variables :
userMain
userPlayer
Inside my rock-button.js file :
const { PermissionOverwrites, Permissions, Collection} = require("discord.js");
const shifumi = require("../../commands/shifumi.js");
module.exports = {
data: {
name: `rock-button`
},
async execute (interaction) {
// import userMain and userPlayer from the shifumi.js file
const { userMain, userPlayer } = shifumi;
console.log(userMain);
await interaction.reply({ content:'Information envoyée !', ephemeral: true});
}
}
I tried to use :
global.userMain = interaction.user;
global.userPlayer = interaction.options.getUser('player');
The result when I try to log the variable are undefined.
and ```js
exports.userMain
exports.userPlayer
But seems doesn't work to :/
I think we cant export a module when we already are in module but I can be wrong.
If somebody can help me I would appreciate :)
Ty
// File A
const userMain = interaction.user;
module.exports = { varToExport: userMain };
// File B
const userMain = require('./fileA').varToExport;
var TOKEN = ""
const client = ("TOKEN");
const { Client, MessageEmbed } = require('discord.js');
const channel = ("CHANNELID");
const embed = new MessageEmbed()
('guildMemberAdd', member => {
const embed = new Discord.RichEmbed()
.setColor('#0099ff')
.setDescription(`Welcome ${member}! You are the ${membercount}th member!`)
.setImage(member.user.avatarURL)
})
That is my current code for this but, I'm unsure because there are some errors to it.
Yes it is possible.
Please don't use this code, it will not work based on how you have it coded now
var TOKEN = ""
const client = ("TOKEN");
const { Client, MessageEmbed } = require('discord.js');
const channel = ("CHANNELID");
const embed = new MessageEmbed()
('guildMemberAdd', member => {
const embed = new Discord.RichEmbed()
.setColor('#0099ff')
.setDescription(`Welcome ${member}! You are the ${membercount}th member!`)
.setImage(member.user.avatarURL)
})
Please use the code below:
// var TOKEN = "" //token is never a variable
// const client = ("TOKEN"); //please find a different way to code this as this will cause confusion later on
const TOKEN = ""
const { Client, MessageEmbed } = require('discord.js');
const client = new Client({
intents: [], // pick the intents you need here https://discord.com/developers/docs/topics/gateway#list-of-intents
})
client.login(TOKEN)
client.on('guildMemberAdd', member => {
const welcomeChannel = client.channels.cache.get("channel_id")
const membercount = member.guild.members.cache.filter(member => !member.user.bot).size
const timeout = 30 * 1000 //30 being how many seconds till the message is deleted.
const embed = new MessageEmbed()
.setColor('#0099ff')
.setTitle(`${member.displayName} has joined us!`)
.setDescription(`Welcome ${member}!\nYou are member number ${membercount}!`)
.setThumbnail(member.displayAvatarURL())
welcomeChannel.send({
embeds: [embed]
}).then((message) => {
setTimeout(() => {
message.delete()
}, timeout);
})
})
Yes, you can!
just use
.then(msg => {
setTimeout(() => {
msg.delete().catch(() => null)
}, 5000)
})
My messageDelete event handler:
client.on("messageDelete", message => {
snipe.set(message.channel.id, {
title: Date.now(),
content: message.content,
author: message.author,
image: message.attachments.first() ? message.attachments.first().proxyURL : null,
});
});
My snipe.js code:
require('discord-reply');
const Discord = require('discord.js')
const moment = require('moment')
module.exports = {
name: 'snipe',
aliases: [],
category: 'Fun',
utilisation: '{prefix}snipe',
description: 'Displays the last deleted message in the current channel!',
execute(client, message) {
const snipe = require('.././../index.js')
const msg = snipe.get(message.channel.id);
const timeAgo = moment(msg.title).fromNow();
if (!msg) return message.channel.send("Theres Nothing To Snipe here...");
if (msg.image) {
const embed1 = new Discord.MessageEmbed()
.setAuthor(msg.author.tag, msg.author.displayAvatarURL({ dynamic: true }))
.setTitle(`Message deleted by ${msg.author.tag}! (${timeAgo})`)
.setDescription(msg.content)
.setColor(0x3498DB)
.setTimestamp()
.setImage(msg.image)
.setFooter("Sniped by " + message.author.tag);
message.lineReply(embed1);
}
else {
const embed = new Discord.MessageEmbed()
.setAuthor(msg.author.tag, msg.author.displayAvatarURL({ dynamic: true }))
.setTitle(`Message deleted by ${msg.author.tag}! (${timeAgo})`)
.setDescription(msg.content)
.setColor(0x3498DB)
.setTimestamp()
.setFooter("Sniped by " + message.author.tag);
message.lineReply(embed);
}
},
}
I am getting the following error in my console when I try running the command
(node:6928) UnhandledPromiseRejectionWarning: TypeError: snipe.get is not a function
Can anyone help? I'm pretty sure my code is correct as I used the same thing in my old bot. Any help would be appreciated.
From what I assume your snipe is a Map/Collection since you are using get/set on it, you may want to export the map to use it in your command file by binding it to your client like so
const snipe = new Map();
Aliter
const { Client, Collection } = require("discord.js");
const snipe = new Collection()
const client = new Client();
// Binding to Client
client.snipe = snipe // aliter declare it directly as client.snipe = new Collection()
Then you may access your collection since you are already exporting client like so
client.snipe.set()
client.snipe.get()
I have an addemoji command and I want it to send the new emoji created after the bot creates it. It sends like :emojiname: instead of the actual emoji added. How can I define the new emoji added? Somebody suggested that I use console.log but I have no idea how to use that information that it puts inside the log.
module.exports = {
name: 'addemoji',
description: 'ping pong',
execute(message, args) {
const Discord = require('discord.js');
const PREFIX = 'ly?';
const load = '<a:loading:824515478939762699>';
if (message.content.startsWith(PREFIX + 'addemoji')) {
if (message.guild.me.permissions.has('USE_EXTERNAL_EMOJIS')) {
if (message.guild.me.permissions.has('MANAGE_EMOJIS')) {
if (message.member.hasPermission('MANAGE_EMOJIS')) {
const match = /<(a?):(.+):(\d+)>/u.exec(message.content);
if (!match)
return message.reply(
'Please include a custom emoji in your message!',
);
// animated will be 'a' if it is animated or '' if it isn't
const [, animated, name, id] = match;
const url = `https://cdn.discordapp.com/emojis/${id}.${
animated ? 'gif' : 'png'
}`;
const user = message.mentions.users.first() || message.author;
const nameid = `<:${name}:${id}>`;
message.guild.emojis.create(url, name);
let newname = console.log(name);
let newid = console.log(id);
const embed = new Discord.MessageEmbed()
.setTitle(`Emoji added! <:${newname}:${newid}>`)
.setColor(0x7732a8);
message.channel.send(embed);
}
}
}
}
}
};
GuildEmojiManager#create() returns a Promise with the newly created emoji. You can access and display the new emoji by handling this promise, then using the <:name:id> wrapper for emoijs
message.guild.emojis.create(url, name).then(newEmoji => {
const embed = new Discord.MessageEmbed()
.setTitle(`Emoji added! <:${newEmoji.name}:${newEmoji.id}>`)
.setColor(0x7732a8)
message.channel.send(embed);
});