Unknown Changes
This commit is contained in:
@@ -21,4 +21,5 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
42
events/presenceUpdate.js
Normal file
42
events/presenceUpdate.js
Normal file
@@ -0,0 +1,42 @@
|
||||
require("dotenv").config();
|
||||
const Discord = require("discord.js");
|
||||
const fetch = require("node-fetch");
|
||||
|
||||
//export a module that checks if a users activity changed and if so, console log the activity
|
||||
module.exports = {
|
||||
name: "presenceUpdate",
|
||||
async execute(oldPresence, newPresence) {
|
||||
if (oldPresence !== newPresence) {
|
||||
console.log(`${newPresence.user.username} changed their activity`);
|
||||
console.log(newPresence);
|
||||
}
|
||||
await newPresence.user.fetch();
|
||||
console.log(newPresence.user.bannerURL({dymanic: true, size: 1024}));
|
||||
console.log(newPresence.user);
|
||||
|
||||
//convert new presence to json string and send it to a channel named "bot-testing"
|
||||
const channel = newPresence.client.channels.cache.find(channel => channel.name === "bot-testing");
|
||||
if (!channel) return;
|
||||
//return if no banner is present
|
||||
if (!newPresence.user.banner) return;
|
||||
//download banner into a buffer
|
||||
const buffer = await (await fetch(newPresence.user.bannerURL({dynamic: true, size: 1024}))).buffer();
|
||||
//upload buffer to discord
|
||||
const attachment = new Discord.MessageAttachment(buffer, "banner.png");
|
||||
|
||||
let uploadChannel = newPresence.client.channels.cache.find(channel => channel.name === "bot-uploads");
|
||||
//send attachment to a channel called "bot-uploads" and save the attachment url to a variable
|
||||
const upload = await uploadChannel.send({
|
||||
files: [attachment]
|
||||
});
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle("User Updated")
|
||||
.setDescription(`banner debug ${newPresence.user.bannerURL({dynamic: true, size: 1024})}`)
|
||||
.setImage(upload.attachments.first().url)
|
||||
.setColor("#FFFFFF");
|
||||
//channel.send({embeds: [embed], content: `${newPresence.user}`});
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,7 @@ const { Routes } = require("discord-api-types/v9")
|
||||
module.exports = {
|
||||
name: "ready",
|
||||
once: true,
|
||||
execute (client, commands) {
|
||||
async execute (client, commands) {
|
||||
console.log("Bot started.");
|
||||
|
||||
const CLIENT_ID = client.user.id;
|
||||
@@ -27,5 +27,8 @@ module.exports = {
|
||||
if (err) console.log(err);
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
61
events/userUpdate.js
Normal file
61
events/userUpdate.js
Normal file
@@ -0,0 +1,61 @@
|
||||
require("dotenv").config();
|
||||
const fetch = require("node-fetch");
|
||||
const Discord = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
name: "userUpdate",
|
||||
async execute (oldUser, newUser) {
|
||||
//get guild by id
|
||||
const guild = newUser.client.guilds.cache.get(process.env.GUILD_ID);
|
||||
|
||||
if (oldUser.username !== newUser.username) {
|
||||
console.log(`${oldUser.username} changed their username to ${newUser.username}`);
|
||||
}
|
||||
if (oldUser.avatar !== newUser.avatar) {
|
||||
console.log(`${oldUser.username} changed their avatar to ${newUser.avatar}`);
|
||||
}
|
||||
|
||||
//check if new user banner is different from old user banner
|
||||
if (newUser.banner !== oldUser.banner) {
|
||||
console.log(`${oldUser.username} changed their banner`);
|
||||
await newUser.fetch();
|
||||
let newUserBanner = newUser.bannerURL();
|
||||
//log user and new banner url
|
||||
console.log(`${newUser.username} has a new banner: ${newUserBanner}`);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//if new avatar is null, console log and return
|
||||
if (newUser.avatar === null) {
|
||||
console.log(`${newUser.username} has no avatar`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//send the new avatar to a channel named "bot-testing"
|
||||
const channel = guild.channels.cache.find(channel => channel.name === "bot-testing");
|
||||
if (!channel) return;
|
||||
let avatarUrl = newUser.avatarURL({dynamic : true, size: 1024});
|
||||
//download avatarUrl into a buffer
|
||||
const buffer = await (await fetch(avatarUrl)).buffer();
|
||||
//upload buffer to discord
|
||||
const attachment = new Discord.MessageAttachment(buffer, "avatar.png");
|
||||
//send attachment to a channel called "bot-uploads" and save the attachment url to a variable
|
||||
const upload = await channel.send({
|
||||
files: [attachment]
|
||||
});
|
||||
|
||||
console.log(newUser);
|
||||
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle("User Updated")
|
||||
.setDescription(`avatar debug asfkdljnsaedlikfnwe;ljkfn`)
|
||||
.setImage(upload.attachments.first().url)
|
||||
.setColor("#FFFFFF");
|
||||
channel.send({embeds: [embed]});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user