added "add" command

main
Benjamin Kraft 9 months ago
parent f965eaacde
commit f244e85b27
  1. 1
      src/bot.ts
  2. 20
      src/commands/add.ts
  3. 8
      src/commands/ping.ts

@ -79,6 +79,7 @@ export class UEMEloBot extends Client {
this.players.push(player); this.players.push(player);
console.log(`Added ${player}!`); console.log(`Added ${player}!`);
this.savePlayersToFile(); this.savePlayersToFile();
return player;
} }
async onReady(readyClient: Client<true>){ async onReady(readyClient: Client<true>){

@ -1,14 +1,28 @@
import {Interaction} from "discord.js"; import {Interaction} from "discord.js";
import {Command} from "../command"; import {Command} from "../command";
import {UEMEloBot} from "../bot";
class Add extends Command { class Add extends Command {
constructor() { constructor() {
super("add", "add a player"); super("add", "Spieler hinzufügen");
this.data.addStringOption(option => {
return option.setName("riot-id").setDescription("Riot ID: 'Name#Tag'").setRequired(true)
});
} }
async execute(interaction: Interaction) { async execute(interaction: Interaction) {
if (!interaction.isChatInputCommand())
return;
if (interaction.isRepliable()) let client = interaction.client as UEMEloBot;
await interaction.reply("Pong!");
const riotId = interaction.options.getString("riot-id", true);
const [gameName, tagLine] = riotId.split("#");
const player = await client.addPlayer(gameName, tagLine);
if (player)
await interaction.reply({content: `${player} Hinzugefügt!`, ephemeral: true});
else
await interaction.reply({content: "Fehler!", ephemeral: true});
} }
} }

@ -3,11 +3,13 @@ import {Command} from "../command";
class Ping extends Command { class Ping extends Command {
constructor() { constructor() {
super("ping", "One simple Ping Pong :)"); super("ping", "Pong");
} }
async execute(interaction: Interaction) { async execute(interaction: Interaction) {
if (interaction.isRepliable()) if (!interaction.isChatInputCommand())
await interaction.reply("Pong!"); return;
await interaction.reply({content: "Pong", ephemeral: true});
} }
} }

Loading…
Cancel
Save