Taking user avatarUrl mentioned in an embed - discord.js

I have a question about adding the avatarUrl from an user mentioned. I've done the code but it doesn't show the image when sending the embed. There's also not error in the console.
const user = message.mentions.users.first();
var mention = "<#" + user.id + ">"
var userCreated = user.createdAt.toString().split(" ");
var userJoined = user.userJoined
const Embed = new Discord.MessageEmbed()
.setTitle(user.tag)
.setDescription(mention)
.setColor("#b60303")
.addFields(
{ name: "Registered at", value: userCreated[1] + " " + userCreated[2] + ", " + userCreated[3]},
{ name: "ID", value: user.id, inline: true}
)
.setImage(message.avatarURL)
.setTimestamp()
.setFooter("ID: " + user.id)
message.channel.send(Embed)
}```

Messages don't have avatar URLs, and in Discord JS v12, avatarURL is a method.
.setImage(message.author.avatarURL())

Related

discord.js v13 How do I verify a guildMember is also a member of another guild?

This is my first post here, sorry in advance if the formatting isn't great.
I'll try to keep it short and sweet. I've made a small bot with discord.js v13 and it's main purpose is to check if new people that join is part of another guild, if they are they get a role and if they had a nickname, they'll get that assigned. The bot is on both servers with full admin rights and the server members intent is enabled. I've tried all sorts of things.
Currently, the code looks like this:
const {other_server_ID, role_ID, text_channel_ID} = require("../config.json");
module.exports = {
name: 'guildMemberAdd',
async execute( member, bot ) {
//Log the newly joined member to console
console.log(member.user.tag + ' has joined the server!');
if(member.bot) return
const text_channel = member.guild.channels.cache.get(text_channel_ID)
const role = member.guild.roles.cache.get(role_ID)
text_channel.send(member.user.tag + ' has joined the server!')
const other_server = bot.guilds.cache.get(other_server_ID)
const other_server_member = other_server.members.cache.get(member.user.id)
console.log(other_server_member)
if (other_server_member === null) text_channel.send(member.user.tag + " was not a member of other_server :(")
else {
text_channel.send(member.user.tag + " was a member of other_server!")
if(!other_server_member.nickname){
text_channel.send(member.tag + " had no nickname on other_server.")
}
else {
await member.setNickname(other_server_member.nickname)
text_channel.send("Their old nickname, " + other_server_member.nickname + ", was returned to them! :)")
}
if(!member.guild.roles.cache.get(role_ID)){
text_channel.send("Role not found.")}
else{
await member.roles.add(role)
text_channel.send("They were given the role " + role.name)
}
}
}
}
As you can see, I am trying to get the other server (it works that far) and then try to grab the user from the other server's cache. Currently I try with get and the user.id but I have also tried:
const other_server_member = other_server.members.cache.find(mem => mem.user.id === member.user.id) || other_server.members.cache.find(mem => mem.user.tag === member.user.tag) || null
I found that code snippet during my search for a solution. So far I always got errors because other_server_member was always undefined/null. I also tried putting await infront of the find/get part.
Thanks for your help and time.
UPDATE:
It works fine with fetch(), code now looks like this:
const {other_server_ID, role_ID, text_channel_ID} = require("../config.json");
module.exports = {
name: 'guildMemberAdd',
async execute( member, bot ) {
//Log the newly joined member to console
console.log(member.user.tag + ' has joined the server!');
if(member.bot) return
const text_channel = member.guild.channels.cache.get(text_channel_ID)
const role = member.guild.roles.cache.get(role_ID)
text_channel.send(member.user.tag + ' has joined the server!')
const other_server = bot.guilds.cache.get(other_server_ID)
const other_server_member = null
try {
other_server_member = await other_server.members.fetch(member.user.id)
} catch (e) {
console.log(e)
return text_channel.send(member.user.tag + " was not a member of " + pluto.name + ".")
}
console.log(other_server_member)
if (other_server_member === null) text_channel.send(member.user.tag + " was not a member of other_server :(")
else {
text_channel.send(member.user.tag + " was a member of other_server!")
if(!other_server_member.nickname){
text_channel.send(member.tag + " had no nickname on other_server.")
}
else {
await member.setNickname(other_server_member.nickname)
text_channel.send("Their old nickname, " + other_server_member.nickname + ", was returned to them! :)")
}
if(!member.guild.roles.cache.get(role_ID)){
text_channel.send("Role not found.")}
else{
await member.roles.add(role)
text_channel.send("They were given the role " + role.name)
}
}
}
}

Integrate smartcontract with reactjs

I want to show data in reactjs application like public variables showing in remixid
enter image description here
when I try to console it's showing
enter image description here
const contractBalance = aw ait contract.getBalance();
const goal = await contract.goal();
const admin = await contract.admin();
const minCont = await contract.minimumContribution();
const nOfCont = await contract.noOfContributors();
const deadline = await contract.deadline();
const numReq = await contract.numRequests();
const raisedAmount = await contract.raisedAmount();
const requestIndex = await contract.requests(0);
console.log('data: ', ethers.utils.formatEther(contractBalance));
console.log('requestIndex > ', requestIndex);
console.log("minCont > " , minCont);
console.log("numReq > " , numReq);
console.log("raisedAmount > " , raisedAmount);
console.log("nOfCont > " , nOfCont);
console.log("admin > " , admin);
console.log("deadline > " , deadline);
please help!
thanks
Because numbers in solidity are treated as BigNumbers.
The most simple way to convert them is by casting them to string:
console.log("minCont > " , minCont.toString());

Send Server Message after Track Users Status (discord.js)

I try to send a Message in a Server. This Server ID is logged in MongoDB and the Channel ID too. But everytime i'll try it, it does not working. Here's my Code:
The Error is the return console.log Text
//This is the guildMemberUpdate file
const client = require("../index.js")
const {MessageEmbed} = require("discord.js")
const {RED, GREEN, BLUE} = require("../commands/jsons/colors.json")
const Schema = require("../models/StatusTracker.js")
client.on("guildMemberUpdate", async(member) => {
const data = await Schema.findOne({Guild: member.guild.id})
let channel = member.guild.channels.cache.get(data.Channel)
if(!channel) return console.log("Es wurde kein Channels gefunden");
if(member.user.presence.status === "offline") {
let offlineEmbed = new MessageEmbed()
.setColor(RED)
.setDescription(member.user.toString() + " ist jetzt offline!")
.setAuthor(member.user.tag, member.user.avatarURL({ dynamic: true }))
channel.send(offlineEmbed)
} else if(member.user.presence.status === "dnd" || member.user.presence.status === "online" || member.user.presence.status === "idle"){
let onlineEmbed = new MessageEmbed()
.setColor(GREEN)
.setDescription(member.user.toString() + " ist jetzt online!")
.setAuthor(member.user.tag, member.user.avatarURL({ dynamic: true }))
channel.send(onlineEmbed)
}
})```
//This is the MongoDB File
"Guild": "851487615358337065",
"Channel": "859444321975009290"
The problem is that you're using the guildMemberUpdate event, but that only tracks nickname and role changes. The one that you're looking for is presenceUpdate. That'll trigger when any user goes offline etc.
Check the docs for more details: here
Note: You'll probably need to enable 'Presence intent' in 'Privileged Gateway Intents' in your bot's settings page for this to work. (https://discord.com/developers/applications)

How would I add a hug reaction command

I have no idea what I’m doing. I don’t code but my friend helped me out up to this part
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('This Bot is online!');
client.user.setActivity('Prefix +k')
});
client.on('message', msg=>{
if(msg.content === "+k Hello"){
msg.reply('Welcome!');
}
})
client.on('message', msg=>{
if(msg.content === "+k Credits"){
msg.reply('Pokemon DB for Info, MrTechGuy for code help!');
}
})
client.on('message', msg=>{
if(msg.content === "+k Credits"){
msg.reply('Pokemon DB for Info, MrTechGuy for code help!');
}
})
client.on('message', msg=>{
if(msg.content === "+k DAList"){
msg.reply('1 - Butterfree <:V:750540886680666282> <:grass:750540661396340826>, 2 = Butterfree <:VMAX:750540886701637743> <:grass:750540661396340826>,');
}
})
client.login('[REDACTED]');
Again, how would I add a hug command that targets the user, e.g. +k hug #user 1, my friend is out for the month and I do not know how to do it
response: #user 2 hugged #user 1 ! (gif here)
For this to work you will need to create a folder named "hug" and with images which are "gif".
if(message.content.startsWith('+k hug')) {
let user = msg.mentions.users.first(); // refers to the user you wish to mention
if (!user) {
let maxImageNumber1 = 7; // represents the number of images in the folder
let hug = Math.floor(Math.random() * (maxImageNumber1 - 1 + 1)) + 1;
let imageName1 = `${hug}.gif` // if the images you put are png/jpg just remove the ".gif" with either ".png" or ".jpg"
let imagePath1 = `/hug/${imageName1}` // folder name
let file1 = new Discord.MessageAttachment(imagePath1);
let embed1 = new Discord.MessageEmbed();
embed1.setImage(`attachment://${imageName1}`)
embed1.setDescription(`**${msg.author.username}** hugged their clone`)
embed1.setColor('RANDOM')
msg.channel.send({ files: [file1], embed: embed1 });
}
if (user) {
let maxImageNumber1 = 7; // represents the number of images in the folder
let hug = Math.floor(Math.random() * (maxImageNumber1 - 1 + 1)) + 1;
let imageName1 = `${hug}.gif` // if the images you put are png/jpg just remove the ".gif" with either ".png" or ".jpg"
let imagePath1 = `/hug/${imageName1}` // folder name
let file1 = new Discord.MessageAttachment(imagePath1);
let embed1 = new Discord.MessageEmbed();
embed1.setImage(`attachment://${imageName1}`)
embed1.setDescription(`**${msg.author.username}** hugged **${user.username}**`)
embed1.setColor('RANDOM')
msg.channel.send({ files: [file1], embed: embed1 });
}
}
Im assuming you are using discord.js v12
TIP:
I'd recommend you define your prefix with something like const prefix = '+k'; and when you want to make a command do this: if(message.content.startsWith(prefix + 'hug')){}

When user type !verify gets verified role

What i want to happen is when user type command "!verify" i want them to give "Verified" role,
i am currently running the latest Discord.js which is version 12.3.1 based on dependencies.
if(message.content.startsWith(`${prefix}verify`)){
let member = message.mentions.members.first();
var role = guild.roles.cache.find('name', 'Verified');
member.addrole(role).then((member)=> {
message.channel.send(":white_check_mark: " + member.displayName + " is now verified!");
})
}
})
There are a few lines in your code that won't work due to having being deprecated methods.
var role = message.guild.roles.cache.find('name', 'Verified');
// should be replace with:
var role = message.guild.roles.cache.find(role => role.name === 'Verified);
and
member.addrole(role).then((member)= > {
message.channel.send(":white_check_mark: " + member.displayName + " is now verified!");
})
// should be replaced with:
member.roles.cache.add(role)
message.channel.send(":white_check_mark: " + member.displayName + " is now verified!");

Resources