Corsy
Corsy
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
Sorry for the late reply I been busy
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
Changed it to that and it seemed to work
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
const spamCh = await message.guild?.channels.fetch(levelupChannel);
if (spamCh && spamCh.isText())
const spamCh = await message.guild?.channels.fetch(levelupChannel);
if (spamCh && spamCh.isText())
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
I've gotten it to work.
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
and they all work
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
I put a log in the experiencehelper.ts where each return would be
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
I have done that.
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
but also doesn't error either, which is weird
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
This is the only thing that does not come up in logs
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
So yeah everything seems to be working fine except the end of code
) {
const spamCh = message.guild?.channels.cache.get(levelupChannel);
console.log("this is working #1")
if (spamCh) {
if (spamCh.type === "GUILD_TEXT") {
spamCh.send({
content: `Hey ${message.author.toString()}, you've leveled up! You are now level ${ExperienceHelper.getLevel(
newExp
)}`,
});
} else {
console.error("Level up channel is not a text channel.");
}
} else {
console.error("Level up channel not found.");
}
}
}
}
) {
const spamCh = message.guild?.channels.cache.get(levelupChannel);
console.log("this is working #1")
if (spamCh) {
if (spamCh.type === "GUILD_TEXT") {
spamCh.send({
content: `Hey ${message.author.toString()}, you've leveled up! You are now level ${ExperienceHelper.getLevel(
newExp
)}`,
});
} else {
console.error("Level up channel is not a text channel.");
}
} else {
console.error("Level up channel not found.");
}
}
}
}
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
I’ll try it here shortly, got busy last night and am now just getting up
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
I mean nothing else within the code has anything else to do with the levelupmessage either, which is why I am confuse because it did all work before in the past
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
getlevel is within the same as well
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
that is the experiencehelper
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
import { GuildMember, MessageAttachment } from "discord.js";
import { logger } from "../papertrail";
import { Rank } from "canvacord";

export const LEVEL_VALUES = [
0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 30000,
];
// export const LEVEL_VALUES = [
// 0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000,
// ];
export const PER_HOUR_PASSIVE_CURRENCY = [
100, 150, 200, 250, 300, 350, 450, 500, 550, 600,
];
export const LEVELING_ROLE_IDS = [
"1246186080848314398",
"1246186125542821981",
"1246186149987225640",
"1246186173664202765",
"1246186196561039520",
"1246186221449773076",
"1246186249518186536",
"1246186279750729758",
"1246186306682228746",
"1246186327062614096",
];
const ROLE_CARD_COLORS = ["#4169e1"];

export default class ExperienceHelper {
public static getLevel(exp: number): number {
for (let i = 0; i < LEVEL_VALUES.length; i++) {
if (exp < LEVEL_VALUES[i]) return i;
}
return LEVEL_VALUES.length;
}

public static getPassiveCurrencyPerHour(level: number): number {
return PER_HOUR_PASSIVE_CURRENCY[level - 1];
}

public static async ensureUserHasLevelRoles(
member: GuildMember,
level: number
) {
const roles = member.roles.cache;
let i = 1;
for (const roleId of LEVELING_ROLE_IDS) {
let levelIdx = i++;
if (!roles.has(roleId)) {
if (levelIdx == level) {
logger.info(`Adding level ${levelIdx} role to ${member.user.tag}`);
await member.roles.add(roleId);
}
} else {
if (levelIdx !== level) {
logger.info(
`Removing level ${levelIdx} role from ${member.user.tag}`
);
await member.roles.remove(roleId);
}
}
}
}

public static getExpToNextLevel(exp: number): number {
const level = ExperienceHelper.getLevel(exp);
return LEVEL_VALUES[level] - exp;
}

public static getExpToNextLevelPercent(exp: number): number {
const level = ExperienceHelper.getLevel(exp);
const nextLevel = LEVEL_VALUES[level];
const percent = (nextLevel - exp) / nextLevel;
return percent;
}

public static getExpToNextLevelPercentString(exp: number): string {
const percent = ExperienceHelper.getExpToNextLevelPercent(exp);
return `${Math.round(percent * 100)}%`;
}

public static async getExperienceCard(
member: GuildMember,
exp: number,
rank: number
): Promise<MessageAttachment[]> {
const level = ExperienceHelper.getLevel(exp);
const nextLevel = LEVEL_VALUES[level] ?? 0;
const percent = nextLevel > 0 ? (nextLevel - exp) / nextLevel : 1;
const percentString = `${Math.round(percent * 100)}%`;
const avatarUrl =
member.avatarURL({ format: "png", size: 128 }) ||
member.user.avatarURL({ format: "png", size: 128 }) ||
"https://cdn.discordapp.com/embed/avatars/0.png";
const card = new Rank()
.setAvatar(avatarUrl)
.setUsername(member.displayName)
.setLevel(level)
.setCurrentXP(exp)
.setRequiredXP(nextLevel)
// .setProgressBar(ROLE_CARD_COLORS)
// .setProgressBar("#b170c0")
.setBackground("COLOR", ROLE_CARD_COLORS[0])
.setOverlay("#050303")
// .setProgressBar(percent)
.setRank(rank)
.setCustomStatusColor(ROLE_CARD_COLORS[0]);
const data = await card.build({ fontX: "Manrope", fontY: "Manrope" });
const file = new MessageAttachment(data, "rank.png");
return [file];
}
}
import { GuildMember, MessageAttachment } from "discord.js";
import { logger } from "../papertrail";
import { Rank } from "canvacord";

export const LEVEL_VALUES = [
0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 30000,
];
// export const LEVEL_VALUES = [
// 0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000,
// ];
export const PER_HOUR_PASSIVE_CURRENCY = [
100, 150, 200, 250, 300, 350, 450, 500, 550, 600,
];
export const LEVELING_ROLE_IDS = [
"1246186080848314398",
"1246186125542821981",
"1246186149987225640",
"1246186173664202765",
"1246186196561039520",
"1246186221449773076",
"1246186249518186536",
"1246186279750729758",
"1246186306682228746",
"1246186327062614096",
];
const ROLE_CARD_COLORS = ["#4169e1"];

export default class ExperienceHelper {
public static getLevel(exp: number): number {
for (let i = 0; i < LEVEL_VALUES.length; i++) {
if (exp < LEVEL_VALUES[i]) return i;
}
return LEVEL_VALUES.length;
}

public static getPassiveCurrencyPerHour(level: number): number {
return PER_HOUR_PASSIVE_CURRENCY[level - 1];
}

public static async ensureUserHasLevelRoles(
member: GuildMember,
level: number
) {
const roles = member.roles.cache;
let i = 1;
for (const roleId of LEVELING_ROLE_IDS) {
let levelIdx = i++;
if (!roles.has(roleId)) {
if (levelIdx == level) {
logger.info(`Adding level ${levelIdx} role to ${member.user.tag}`);
await member.roles.add(roleId);
}
} else {
if (levelIdx !== level) {
logger.info(
`Removing level ${levelIdx} role from ${member.user.tag}`
);
await member.roles.remove(roleId);
}
}
}
}

public static getExpToNextLevel(exp: number): number {
const level = ExperienceHelper.getLevel(exp);
return LEVEL_VALUES[level] - exp;
}

public static getExpToNextLevelPercent(exp: number): number {
const level = ExperienceHelper.getLevel(exp);
const nextLevel = LEVEL_VALUES[level];
const percent = (nextLevel - exp) / nextLevel;
return percent;
}

public static getExpToNextLevelPercentString(exp: number): string {
const percent = ExperienceHelper.getExpToNextLevelPercent(exp);
return `${Math.round(percent * 100)}%`;
}

public static async getExperienceCard(
member: GuildMember,
exp: number,
rank: number
): Promise<MessageAttachment[]> {
const level = ExperienceHelper.getLevel(exp);
const nextLevel = LEVEL_VALUES[level] ?? 0;
const percent = nextLevel > 0 ? (nextLevel - exp) / nextLevel : 1;
const percentString = `${Math.round(percent * 100)}%`;
const avatarUrl =
member.avatarURL({ format: "png", size: 128 }) ||
member.user.avatarURL({ format: "png", size: 128 }) ||
"https://cdn.discordapp.com/embed/avatars/0.png";
const card = new Rank()
.setAvatar(avatarUrl)
.setUsername(member.displayName)
.setLevel(level)
.setCurrentXP(exp)
.setRequiredXP(nextLevel)
// .setProgressBar(ROLE_CARD_COLORS)
// .setProgressBar("#b170c0")
.setBackground("COLOR", ROLE_CARD_COLORS[0])
.setOverlay("#050303")
// .setProgressBar(percent)
.setRank(rank)
.setCustomStatusColor(ROLE_CARD_COLORS[0]);
const data = await card.build({ fontX: "Manrope", fontY: "Manrope" });
const file = new MessageAttachment(data, "rank.png");
return [file];
}
}
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
So where would I go about fixing this exactly? I am just stuck here tbh, been trying to look at it multiple times, changing things etc
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
#3 and #2 does
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
#2 does
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
I have clarified that the levelupchannel is correct
38 replies
DIAdiscord.js - Imagine an app
Created by Corsy on 6/9/2024 in #djs-questions
level up message
any ideas?
38 replies