TypeScript ModMail

In TypeScript: How do I have a bot send a message for a user to react, remove the reaction once reacted, and then D.M. the user? I'm trying to make a modmail bot in TypeScript but have no idea how.
21 Replies
Favna
Favna12mo ago
Partially to save myself code dumping and partially to check where your progress is - do you know how to do this in another language? Say JavaScript or Python or whatever.
Living Water
Living Water12mo ago
Honestly, no.
Favna
Favna12mo ago
I haven't vetted it but maybe check out this https://youtu.be/0ckwqupNEFk Once you do know how to do in other languages and develop some programming skills you can then work on climbing the typescript learning curve. Jumping straight into typescript is quite steep.
MrJAwesome
YouTube
[NEW] - How to make MODMAIL SYSTEM for your discord bot || Discord....
This is how you can make a MODMAIL system for your discord.js v14 bot! If you need help, join the server below. The mongoose guide & tutorial is linked below as well. Invite my bots!: 🡺 https://top.gg/bot/977594345756688384 (ESKI) 🡺 https://discord.com/api/oauth2/authorize?client_id=986762502455033916&permissions=8&scope=bot%20applications.co...
Living Water
Living Water12mo ago
However, there is this one very small YouTuber who showed his TypeScript code for a ModMail bot, but I got 18 errors in 8 files! And I have no idea how to fix the errors.
Favna
Favna12mo ago
Show the errors I suppose
Living Water
Living Water12mo ago
Thanks! One moment, please.
Living Water
Living Water12mo ago
Favna
Favna12mo ago
Uh as file. I'm on mobile. No problem. I'll check after breakfast and all that on laptop. Probably easier anyway.
Living Water
Living Water12mo ago
????? Sorry, I'm confused.
Favna
Favna12mo ago
Can't view it on mobile lol
No description
Living Water
Living Water12mo ago
Right. I'm confused by "Uh as file" and also am confused by what time you will be eating breakfast.
Favna
Favna12mo ago
I'll come back to this in like 1,5 hours probably
Living Water
Living Water12mo ago
All right. @Favna You'll need the code to properly debug, though. It can be found here: https://github.com/TFAGaming/DiscordTS-Template Thanks. @Favna wait no that's not it https://github.com/TFAGaming/DiscordTS-ModMail-Bot/tree/main @Favna this is it
Favna
Favna12mo ago
all of the errors are simply cases you need to cover @sourcelight. All the null and undefined checks means you need to check for them being null or undefined using if checks, this also means rather than using something like user?.id wrapping it in an if (user) then just using user.id inside that if. The process.env.X errors are also correct, env vars can be undefined. You need to check that too. at the bottom where it says Cannot find name 'pmessage'. Did you mean 'message'? is because there is a typo and lastly the error Property 'parentId' does not exist on type 'TextBasedChannel'. is because you need to use interaction?.channel.isThread() in an if statement to validate that the interaction runs in a thread. https://old.discordjs.dev/#/docs/discord.js/main/class/TextChannel?scrollTo=isThread
drainpixie
drainpixie12mo ago
Hard to explain because you just said yourself what you're supposed to do send -> react collect reactions -> if filters returns true remove reaction -> send message did they just copy/paste JavaScript code into a TypeScript file?
Living Water
Living Water12mo ago
I had gotten thirty errors before; when I put the ? before the dots, almost half of the errors went away. @Favna So, how exactly do I fix the errors? "and lastly the error Property 'parentId' does not exist on type 'TextBasedChannel'. is because you need to use interaction?.channel.isThread()"
this only gave me a new error
"The process.env.X errors are also correct, env vars can be undefined. You need to check that too."
i again want to clarify that i do not know how to fix the errors
"at the bottom where it says Cannot find name 'pmessage'. Did you mean 'message'? is because there is a typo"
changing that worked
Favna
Favna12mo ago
If statements to verify that things exist.
Living Water
Living Water12mo ago
..... i dont know how
Spinel
Spinel12mo ago
Before you make a Discord Bot, you should have a good understanding of JavaScript. This means you should have a basic understanding of the following topics: - Read and understand docs - Debug code - Syntax - NodeJS module system If you aren't sure that your understanding of JavaScript is truly good enough to make a bot, you should really try to continue learning first. Here are good resources to learn both Javascript and NodeJS: Codecademy: https://www.codecademy.com/learn/javascript Udemy: https://www.udemy.com/javascript-essentials/ Eloquent JavaScript, free book: http://eloquentjavascript.net/ You-Dont-Know-JS: https://github.com/getify/You-Dont-Know-JS JavaScript Garden: https://bonsaiden.github.io/JavaScript-Garden/ JavaScript reference/docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference Nodeschool: https://nodeschool.io/ Pluralsight: https://www.codeschool.com/courses/real-time-web-with-node-js Before you ask a question, you should ask these yourself: 1) Is this question related to JavaScript, or the library I am using? - If it is the library you are using, go to the proper server. You would get better answers there. 2) Have I tried to google and / or check StackOverflow? - Double check that you can't find anywhere that can lead you to a solution online. 3) Have I tried to look on MDN or the library documentation? - You should always check documentations to make sure you aren't missing how any details. 4) Does my question make enough sense so that people can understand it, and do they understand what I am trying to accomplish? - If no, revise your question. Give as much detail as possible. Include any error or code output that can help us help you. 5) Am I aware of what I am doing, and not just mindlessly copy and pasting? - If you are just copy and pasting code from a guide, you are not going to be able to solve anything. Make sure you understand the code you are writing.
Living Water
Living Water12mo ago
@Favna all right so i have this typescript code that compiles perfectly... but it won't run! one of my typescript files seems to be issuing an error in its corresponding javascript file
No description
No description
Living Water
Living Water12mo ago
import { Client, Collection, REST, Routes } from "discord.js";
import { Command } from "../types";
import { readdirSync } from 'node:fs';
import { token, guild, app } from "../config.json";

export default class extends Client {
public commands: Collection<string, Command> = new Collection();
public commandsArray: Command['structure'][] = [];

constructor() {
super({
intents: [
'Guilds'
]
});
};

public loadModules() {
// Commands
for (const dir of readdirSync('./dist/commands/')) {
for (const file of readdirSync('./dist/commands/' + dir)) {
const module: Command = require('../commands/' + dir + '/' + file).default;

this.commands.set(module.structure.name, module);
this.commandsArray.push(module.structure);

console.log('Loaded new command: ' + file);
};
};

// Events
for (const dir of readdirSync('./dist/events/')) {
for (const file of readdirSync('./dist/events/' + dir)) {
require('../events/' + dir + '/' + file);

console.log('Loaded new event: ' + file);
};
};
};

public command = class {
public structure: Command['structure'];
public run: Command['run'];

constructor(data: Command) {
this.structure = data.structure;
this.run = data.run;
};
};

public async deploy() {
const rest = new REST().setToken(token ?? '');

try {
console.log('Started loading app commands...');

await rest.put(Routes.applicationCommands(app ?? ''), {
body: this.commandsArray
});

console.log('Finished loading app commands.');
} catch (e) {
console.error(e);
};
};

public async start() {
await this.login(token);
};
};
import { Client, Collection, REST, Routes } from "discord.js";
import { Command } from "../types";
import { readdirSync } from 'node:fs';
import { token, guild, app } from "../config.json";

export default class extends Client {
public commands: Collection<string, Command> = new Collection();
public commandsArray: Command['structure'][] = [];

constructor() {
super({
intents: [
'Guilds'
]
});
};

public loadModules() {
// Commands
for (const dir of readdirSync('./dist/commands/')) {
for (const file of readdirSync('./dist/commands/' + dir)) {
const module: Command = require('../commands/' + dir + '/' + file).default;

this.commands.set(module.structure.name, module);
this.commandsArray.push(module.structure);

console.log('Loaded new command: ' + file);
};
};

// Events
for (const dir of readdirSync('./dist/events/')) {
for (const file of readdirSync('./dist/events/' + dir)) {
require('../events/' + dir + '/' + file);

console.log('Loaded new event: ' + file);
};
};
};

public command = class {
public structure: Command['structure'];
public run: Command['run'];

constructor(data: Command) {
this.structure = data.structure;
this.run = data.run;
};
};

public async deploy() {
const rest = new REST().setToken(token ?? '');

try {
console.log('Started loading app commands...');

await rest.put(Routes.applicationCommands(app ?? ''), {
body: this.commandsArray
});

console.log('Finished loading app commands.');
} catch (e) {
console.error(e);
};
};

public async start() {
await this.login(token);
};
};
@drainpixie @Favna @drainpixie Never mind. Sorry. I fixed it.