feat(events/client): adding the client import on the ready event
This commit is contained in:
parent
a8a1815287
commit
dc1c048f78
1 changed files with 12 additions and 10 deletions
|
|
@ -9,13 +9,14 @@ import {
|
||||||
Collection,
|
Collection,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { prisma } from '@lib/prisma';
|
import { prisma } from '@lib/prisma';
|
||||||
|
import { client } from '@lib/client';
|
||||||
import { Bot as BotPrisma } from '@prisma/client';
|
import { Bot as BotPrisma } from '@prisma/client';
|
||||||
import { log } from '@lib/log';
|
import { log } from '@lib/log';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
once: true,
|
once: true,
|
||||||
async execute(client: User) {
|
async execute(clientUser: User) {
|
||||||
try {
|
try {
|
||||||
const botData: BotPrisma | null = await prisma.bot.upsert({
|
const botData: BotPrisma | null = await prisma.bot.upsert({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -70,7 +71,7 @@ export default {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (botData.type === 'steam') {
|
if (botData.type === 'steam') {
|
||||||
client.user.setPresence({
|
clientUser.user.setPresence({
|
||||||
status: newPresence,
|
status: newPresence,
|
||||||
activities: [
|
activities: [
|
||||||
{
|
{
|
||||||
|
|
@ -82,7 +83,7 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
client.user.setPresence({
|
clientUser.user.setPresence({
|
||||||
status: newPresence,
|
status: newPresence,
|
||||||
activities: [
|
activities: [
|
||||||
{
|
{
|
||||||
|
|
@ -93,12 +94,13 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const buyerNotification: EmbedBuilder = new EmbedBuilder()
|
const buyerNotification: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle(`${client.user.username} running`)
|
.setTitle(`${clientUser.user.username} running`)
|
||||||
.setColor('#008000')
|
.setColor('#008000')
|
||||||
|
.setTimestamp()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`
|
`
|
||||||
**On:** ${client.guilds.cache.size} guild${client.guilds.cache.size > 1 ? 's' : ''}
|
**On:** ${clientUser.guilds.cache.size} guild${clientUser.guilds.cache.size > 1 ? 's' : ''}
|
||||||
**With:** ${client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)} users
|
**With:** ${clientUser.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)} users
|
||||||
`,
|
`,
|
||||||
)
|
)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
@ -106,13 +108,13 @@ export default {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
botData.buyers.map(async (buyer: User) => {
|
botData.buyers.map(async (buyer: User) => {
|
||||||
try {
|
try {
|
||||||
const user = await client.client.users.fetch(buyer.id);
|
const user = await client.users.fetch(buyer.id);
|
||||||
const dm: DMChannel = await user.createDM();
|
const dm: DMChannel = await user.createDM();
|
||||||
const messages: Collection<string, Message<boolean>> = await dm.messages.fetch({
|
const messages: Collection<string, Message<boolean>> = await dm.messages.fetch({
|
||||||
limit: 20,
|
limit: 20,
|
||||||
});
|
});
|
||||||
const lastBotMsg: Message<boolean> | undefined = messages.find(
|
const lastBotMsg: Message<boolean> | undefined = messages.find(
|
||||||
(m: Message): boolean => m.author.id === client.client.user!.id,
|
(m: Message): boolean => m.author.id === client.user!.id,
|
||||||
);
|
);
|
||||||
if (!lastBotMsg) {
|
if (!lastBotMsg) {
|
||||||
await lastBotMsg.edit({
|
await lastBotMsg.edit({
|
||||||
|
|
@ -138,7 +140,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.search('Guild');
|
log.search('Guild');
|
||||||
for (const [guildId, guild] of client.guilds.cache) {
|
for (const [guildId, guild] of clientUser.guilds.cache) {
|
||||||
try {
|
try {
|
||||||
await prisma.guild.upsert({
|
await prisma.guild.upsert({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -191,6 +193,6 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('\n\n');
|
console.log('\n\n');
|
||||||
log.success(`${client.user.username} is now running under TTS bot`);
|
log.success(`${clientUser.user.username} is now running under TTS bot`);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue