Using Typescript in Sapphire.

I was changing between Javascript to Typescript in the framework, and ping command don't work. My code: ping.ts
import { Command } from '@sapphire/framework';
import type { Message } from 'discord.js';
export class PingCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: 'ping',
aliases: ['pong'],
description: 'ping pong'
});
}
public async messageRun(message: Message) {
const msg = await message.channel.send('Ping?');
const content = `Pong from JavaScript! Bot Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${
msg.createdTimestamp - message.createdTimestamp
}ms.`;
return msg.edit(content);
}
}
import { Command } from '@sapphire/framework';
import type { Message } from 'discord.js';
export class PingCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: 'ping',
aliases: ['pong'],
description: 'ping pong'
});
}
public async messageRun(message: Message) {
const msg = await message.channel.send('Ping?');
const content = `Pong from JavaScript! Bot Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${
msg.createdTimestamp - message.createdTimestamp
}ms.`;
return msg.edit(content);
}
}
index.js
import { SapphireClient } from '@sapphire/framework';

const client = new SapphireClient({
defaultPrefix: "-",
caseInsensitiveCommands: true,
loadMessageCommandListeners: true,
intents: 8705
});

async function runBot() {
await client.login('');
console.log("Bot | Online");
}
runBot();
import { SapphireClient } from '@sapphire/framework';

const client = new SapphireClient({
defaultPrefix: "-",
caseInsensitiveCommands: true,
loadMessageCommandListeners: true,
intents: 8705
});

async function runBot() {
await client.login('');
console.log("Bot | Online");
}
runBot();
4 Replies
Spinel
Spinel•2y ago
- Did you use a folder of the examples repository or did you use the CLI to generate your bot? - What's your file/folder structure? - What's your "main" property in package.json - Are you using TypeScript? And if so, how are you compiling and running your code? - Are you using the version 2 or version 3 of @sapphire/framework? - In case you are using version 3 of @sapphire/framework, and your problem related to message commands, did you add loadMessageCommandListeners to your SapphireClient options Remember that if you are new to @sapphire/framework it is important that you read the user guide.
Krish
Krish•2y ago
why is your index file js?
Lioness100
Lioness100•2y ago
I don't think it is Oh nevermind
savageđź—ˇ
savage🗡•2y ago
nah nevermind I saw the new guide and damn it's way too hard (for me, first time using ts), I need a weekend to work in it, however thanks
Want results from more Discord servers?
Add your server