bot nepojde když nebude moct poslat dm

This commit is contained in:
Histmy 2022-11-26 16:52:58 +01:00
parent d7dfeb79ee
commit 88d0954d6b
4 changed files with 21 additions and 15 deletions

View File

@ -17,8 +17,6 @@ const changeActivity = (mes: Message, activity: Exclude<ActivityType, ActivityTy
return "ano pane";
};
const sleep = (time: number) => new Promise<void>(res => setTimeout(res, time));
const exp: Modul = {
more_komandy: {
@ -128,7 +126,7 @@ const exp: Modul = {
pockej: {
als: ["cekej"],
arg: "počet sekund",
run: (mes, arg) => {
run: async (mes, arg) => {
if (mes.author.id == mes.client.user?.id) return emouty.sjeta;
let cas: number;
if (arg.length) {
@ -138,11 +136,16 @@ const exp: Modul = {
cas = Math.floor(Math.random() * 10740 + 60);
}
const channel = await mes.author.createDM();
try {
await channel.send(`test ${emouty.d3k}`);
} catch {
return "ja ti ale napsat nemuzu ti kundo";
}
setTimeout(async () => {
const chanel = await mes.author.createDM();
for (let i = 0; i < 15; i++) {
chanel.send("uz?");
await sleep(200);
await channel.send("uz?");
}
}, cas * 1000);

View File

@ -4,7 +4,7 @@ import { ChannelType, Message, Presence, Role, TextBasedChannel, User, VoiceStat
import fetch from "node-fetch";
import { emouty } from "../utils/emotes";
import { Modul, Spinkackar, SRecord } from "../utils/types";
import { formatCas, formatter, log, oddiakritikovat, ping } from "../utils/utils";
import { formatCas, formatter, log, oddiakritikovat, ping, sendDM } from "../utils/utils";
let spinkacky: SRecord<Spinkackar>;
const budouciSpinky: SRecord<NodeJS.Timeout> = {};
@ -237,8 +237,7 @@ const exp: Modul = {
mes.delete();
(async () => {
const chanel = mes.author.dmChannel ?? await mes.author.createDM();
chanel.send("spis tak nepis");
sendDM(mes.author, "spis tak nepis");
})();
return true;
}

View File

@ -6,7 +6,7 @@ import { emouty } from "../utils/emotes";
import { createServer } from "http";
import { Modul } from "../utils/types";
import fetch from "node-fetch";
import { formatCas, log } from "../utils/utils";
import { formatCas, log, sendDM } from "../utils/utils";
let spim = false;
@ -100,9 +100,7 @@ const exp: Modul = {
on_userUpdate: (bef: User, aft: User) => {
if (bef.avatar == aft.avatar) return;
aft.createDM().then(ch => {
ch.send("cus bracho vydim ze sis zmenim profilofku na dalsi mrdku estli chces abi se ukazovala na na v3ech sr4kach kterz sou na dedfis.cy tak se tam prosymte prihlas haby se mohla zmnenit syk");
});
sendDM(aft, "cus bracho vydim ze sis zmenim profilofku na dalsi mrdku estli chces abi se ukazovala na na v3ech sr4kach kterz sou na dedfis.cy tak se tam prosymte prihlas haby se mohla zmnenit syk");
}
};

View File

@ -1,5 +1,5 @@
import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, entersState, getVoiceConnection, joinVoiceChannel, PlayerSubscription, StreamType, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice";
import { ChannelType, Client, Guild, StageChannel, VoiceChannel } from "discord.js";
import { ChannelType, Client, Guild, StageChannel, User, VoiceChannel } from "discord.js";
import { once } from "events";
import { FakePresence, JoinHovna, KomandNaExport, MuzikaFace, RunFunkce, SRecord, StatusyINaFounu } from "./types";
import { existsSync } from "fs";
@ -184,7 +184,8 @@ export function adminLog(client: Client, text: string) {
adminChannel.send(text);
}
if (process.env.adminID) {
client.users.cache.get(process.env.adminID)?.createDM().then(ch => ch.send(text));
const user = client.users.cache.get(process.env.adminID);
if (user) sendDM(user, text);
}
}
@ -239,3 +240,8 @@ export const statusOnFoun = (bef: FakePresence | null, aft: FakePresence) => {
};
export const getGuildConnection = (guildId: string) => pripojeni[guildId]?.connection;
export async function sendDM(user: User, txt: string) {
const channel = await user.createDM();
channel.send(txt).catch(() => console.log(`dementovi ${user} nejde poslat DM`));
}