Preview
Open Original
| import { Client, Message, User } from "discord.js" | |
| import chalk from "chalk" | |
| const client: Client = new Client() | |
| client.on(‘ready’, () => { | |
| console.log(chalk.green(`started bot on ${client.user.tag}`)) | |
| }) | |
| client.on(‘message’, async function(message: Message) { | |
| if (!message.guild) return | |
| if (message.author.bot) return | |
| if (!message.content.startsWith(‘!’)) return | |
| const args: Array<string> = message.content.slice(`!`.length).trim().split(" ") | |
| const commandName: string = args.shift().toLowerCase() | |
| console.log(chalk.yellow(`command ${commandName} with args [${args}... |
| import { Client, Message, User } from "discord.js" | |
| import chalk from "chalk" | |
| const client: Client = new Client() | |
| client.on(‘ready’, () => { | |
| console.log(chalk.green(`started bot on ${client.user.tag}`)) | |
| }) | |
| client.on(‘message’, async function(message: Message) { | |
| if (!message.guild) return | |
| if (message.author.bot) return | |
| if (!message.content.startsWith(‘!’)) return | |
| const args: Array<string> = message.content.slice(`!`.length).trim().split(" ") | |
| const commandName: string = args.shift().toLowerCase() | |
| console.log(chalk.yellow(`command ${commandName} with args [${args}]`)) | |
| if ([‘ping’, ‘pong’].includes(commandName)) { | |
| let start: number = new Date().getTime() | |
| const msg: Message = await message.channel.send(‘Pong!’) | |
| const end: number = new Date().getTime() - start | |
| msg.edit(`Pong! Took ${end}ms`) | |
| } else if ([‘av’, ‘avatar’].includes(commandName)) { | |
| let user: User | string = ((message.mentions.users.first()) ? message.mentions.users.first() : args[0]) | |
| if(!user){ | |
| user = message.author | |
| } else if(typeof user == ‘string’){ | |
| user = user.replace(‘<@’, ‘’).replace(‘>’, ‘’).replace(‘!’, ‘’) | |
| user = await client.users.fetch(user) | |
| } | |
| // const user = message.mentions.users.first() ? args[0] ? await client.users.fetch(args[0]) ?? message.author : message.author : message.author | |
| // messy code smh | |
| // const user = message.mentions.users.first() ? message.content.trim().split(’ ‘)[1] ? await client.users.fetch(message.content.trim().split(’ ’)[1]) ?? message.author : message.author : message.author | |
| const avatar: string = user.displayAvatarURL({ format: ‘png’, size: 2048 }) | |
| message.channel.send(avatar) | |
| } else if ([‘echo’].includes(commandName)) { | |
| let text: string = args.join(" ") | |
| message.channel.send(`Your message is: `${text}``, { | |
| disableMentions: `all` | |
| }) | |
| } | |
| }) | |
| client.login(process.env.TOKEN) |