McDefault - Hello y'all Im trying to follow the c...

Hello y'all> Im trying to follow the create basic slash cmd guide, but the example code is giving an error on isMessageInstance(msg) Type not assignable https://www.sapphirejs.dev/docs/Guide/getting-started/creating-a-basic-app-command
import { isMessageInstance } from '@sapphire/discord.js-utilities';
import { ChatInputCommand, Command } from "@sapphire/framework";

export class PingCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, { ...options });
}
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName('ping').setDescription('Ping bot to see if it is alive')
);
}
public async chatInputRun(interaction: Command.ChatInputInteraction) {
const msg = await interaction.reply({ content: `Ping?`, ephemeral: false, fetchReply: true });
if (isMessageInstance(msg)) {
const diff = msg.createdTimestamp - interaction.createdTimestamp;
const ping = Math.round(this.container.client.ws.ping);
return interaction.editReply(`Pong 🏓! (Round trip took: ${diff}ms. Heartbeat: ${ping}ms.)`);
}
return interaction.editReply('Failed to retrieve ping :(');
}
}
import { isMessageInstance } from '@sapphire/discord.js-utilities';
import { ChatInputCommand, Command } from "@sapphire/framework";

export class PingCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, { ...options });
}
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName('ping').setDescription('Ping bot to see if it is alive')
);
}
public async chatInputRun(interaction: Command.ChatInputInteraction) {
const msg = await interaction.reply({ content: `Ping?`, ephemeral: false, fetchReply: true });
if (isMessageInstance(msg)) {
const diff = msg.createdTimestamp - interaction.createdTimestamp;
const ping = Math.round(this.container.client.ws.ping);
return interaction.editReply(`Pong 🏓! (Round trip took: ${diff}ms. Heartbeat: ${ping}ms.)`);
}
return interaction.editReply('Failed to retrieve ping :(');
}
}
Sapphire Framework
Creating a basic slash command | Sapphire
This section covers the absolute minimum for setting up a slash command. We have an entire "Application Commands"
23 Replies
McDefault
McDefaultOP3y ago
Error when loading 'E:\Users\Max\Documents\simple-typescript-starter\src\commands\ping.ts': src/commands/ping.ts:15:27 - error TS2345: Argument of type 'APIMessage | Message<boolean>' is not assignable to parameter of type 'Messa
ge<boolean> | APIMessage'.
Type 'APIMessage' is not assignable to type 'Message<boolean> | APIMessage'.
Type 'import("E:/Users/Max/Documents/simple-typescript-starter/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/channel").APIMessage' is not assignable to type 'import("E:/Users/Max/Documents/simple-typescri
pt-starter/node_modules/discord-api-types/payloads/v9/channel").APIMessage'.
The types of 'author.flags' are incompatible between these types.
Type 'import("E:/Users/Max/Documents/simple-typescript-starter/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined' is not assignable to type 'import("E:/Users/Max/Documents/sim
ple-typescript-starter/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined'.
Type 'import("E:/Users/Max/Documents/simple-typescript-starter/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags' is not assignable to type 'UserFlags'.

15 if (isMessageInstance(msg)) {
Error when loading 'E:\Users\Max\Documents\simple-typescript-starter\src\commands\ping.ts': src/commands/ping.ts:15:27 - error TS2345: Argument of type 'APIMessage | Message<boolean>' is not assignable to parameter of type 'Messa
ge<boolean> | APIMessage'.
Type 'APIMessage' is not assignable to type 'Message<boolean> | APIMessage'.
Type 'import("E:/Users/Max/Documents/simple-typescript-starter/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/channel").APIMessage' is not assignable to type 'import("E:/Users/Max/Documents/simple-typescri
pt-starter/node_modules/discord-api-types/payloads/v9/channel").APIMessage'.
The types of 'author.flags' are incompatible between these types.
Type 'import("E:/Users/Max/Documents/simple-typescript-starter/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined' is not assignable to type 'import("E:/Users/Max/Documents/sim
ple-typescript-starter/node_modules/discord-api-types/payloads/v9/user").UserFlags | undefined'.
Type 'import("E:/Users/Max/Documents/simple-typescript-starter/node_modules/discord.js/node_modules/discord-api-types/payloads/v9/user").UserFlags' is not assignable to type 'UserFlags'.

15 if (isMessageInstance(msg)) {
{
"name": "typescript-starter",
"version": "1.0.0",
"description": "A basic typescript app starter for newbies in 2022.",
"main": "src/index.js",
"scripts": {
"build": "rimraf ./build && tsc",
"start:dev": "nodemon",
"start": "npm run build && node build/index.js",
"lint": "eslint . --ext .ts",
"prettier-format": "run-script-os",
"prettier-format:win32": "prettier --config .prettierrc \"./src/**/*.ts\" --write",
"prettier-format:darwin:linux": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-format:default": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-watch": "run-script-os",
"prettier-watch:win32": "onchange \"src/**/*.ts\" -- prettier --write {{changed}}",
"prettier-watch:darwin:linux": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"prettier-watch:default": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"test": "jest",
"test:dev": "jest --watchAll"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && npm run prettier-format && npm run lint"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/node": "^18.6.1",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.6.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^28.1.3",
"nodemon": "^2.0.19",
"onchange": "^7.1.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"dependencies": {
"@sapphire/framework": "^3.1.3",
"discord.js": "^13.9.0"
}
}
{
"name": "typescript-starter",
"version": "1.0.0",
"description": "A basic typescript app starter for newbies in 2022.",
"main": "src/index.js",
"scripts": {
"build": "rimraf ./build && tsc",
"start:dev": "nodemon",
"start": "npm run build && node build/index.js",
"lint": "eslint . --ext .ts",
"prettier-format": "run-script-os",
"prettier-format:win32": "prettier --config .prettierrc \"./src/**/*.ts\" --write",
"prettier-format:darwin:linux": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-format:default": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-watch": "run-script-os",
"prettier-watch:win32": "onchange \"src/**/*.ts\" -- prettier --write {{changed}}",
"prettier-watch:darwin:linux": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"prettier-watch:default": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"test": "jest",
"test:dev": "jest --watchAll"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && npm run prettier-format && npm run lint"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/node": "^18.6.1",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^26.6.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^28.1.3",
"nodemon": "^2.0.19",
"onchange": "^7.1.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"dependencies": {
"@sapphire/framework": "^3.1.3",
"discord.js": "^13.9.0"
}
}
Favna
Favna3y ago
deduplicate your dependencies. You have conflicting versions of discord-api-types also good lord man clean up those scripts. all that prettier-format:win32 is completely unnecessary prettier \"./src/**/*.ts\" --write works on all platforms and automatically loads .prettierrc
McDefault
McDefaultOP3y ago
Thank you for your reply. What duplicates are you referring to exactly? I'm not sure which one your mean
"@types/jest": "^28.1.6",
"@types/node": "^18.6.1",
"@types/jest": "^28.1.6",
"@types/node": "^18.6.1",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
these?
Favna
Favna3y ago
those arent the same so no
Favna
Favna3y ago
im referring to running https://docs.npmjs.com/cli/v9/commands/npm-dedupe?v=true or the yarn equivalent
npm-dedupe | npm Docs
Reduce duplication in the package tree
McDefault
McDefaultOP3y ago
Right. Thank you for the suggestion. I have run it now and still seem to have issues
Favna
Favna3y ago
uh update your deps most of them are outdated sapphire is on 3.1.4, djs is 13.12.0, etc. npx npm-upgrade when using npm pretty sure djs 13.9 just has a different discord-api-types transient dep than sapphire 3.1.3 does
McDefault
McDefaultOP3y ago
yeah was about to ask that thx not v14 right
Favna
Favna3y ago
no 13.12.0 I guess npm-upgrade might not list that... common npm L compared to yarn mmLol
McDefault
McDefaultOP3y ago
ill just do it myself lol apart from that npx npm-upgrade is pretty handy
Favna
Favna3y ago
just use https://marketplace.visualstudio.com/items?itemName=pflannery.vscode-versionlens otherwise, it offers a similar but offers different options for semver scoping
Version Lens - Visual Studio Marketplace
Extension for Visual Studio Code - Shows the latest version for each package using code lens
Favna
Favna3y ago
(gif in the readme)
McDefault
McDefaultOP3y ago
Im on webstorm
Favna
Favna3y ago
oh webstorm has it integrated lol
McDefault
McDefaultOP3y ago
still same error lol
{
"name": "typescript-starter",
"version": "1.0.0",
"description": "A basic typescript app starter for newbies in 2022.",
"main": "src/index.js",
"scripts": {
"build": "rimraf ./build && tsc",
"start:dev": "nodemon",
"start": "npm run build && node build/index.js",
"lint": "eslint . --ext .ts",
"prettier-format": "run-script-os",
"prettier-format:win32": "prettier --config .prettierrc \"./src/**/*.ts\" --write",
"prettier-format:darwin:linux": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-format:default": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-watch": "run-script-os",
"prettier-watch:win32": "onchange \"src/**/*.ts\" -- prettier --write {{changed}}",
"prettier-watch:darwin:linux": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"prettier-watch:default": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"test": "jest",
"test:dev": "jest --watchAll"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && npm run prettier-format && npm run lint"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.2",
"jest": "^29.3.1",
"nodemon": "^2.0.20",
"onchange": "^7.1.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
},
"dependencies": {
"@sapphire/framework": "^3.1.4",
"discord.js": "^13.12.0"
}
}
{
"name": "typescript-starter",
"version": "1.0.0",
"description": "A basic typescript app starter for newbies in 2022.",
"main": "src/index.js",
"scripts": {
"build": "rimraf ./build && tsc",
"start:dev": "nodemon",
"start": "npm run build && node build/index.js",
"lint": "eslint . --ext .ts",
"prettier-format": "run-script-os",
"prettier-format:win32": "prettier --config .prettierrc \"./src/**/*.ts\" --write",
"prettier-format:darwin:linux": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-format:default": "prettier --config .prettierrc 'src/**/*.ts' --write",
"prettier-watch": "run-script-os",
"prettier-watch:win32": "onchange \"src/**/*.ts\" -- prettier --write {{changed}}",
"prettier-watch:darwin:linux": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"prettier-watch:default": "onchange 'src/**/*.ts' -- prettier --write {{changed}}",
"test": "jest",
"test:dev": "jest --watchAll"
},
"husky": {
"hooks": {
"pre-commit": "npm run test && npm run prettier-format && npm run lint"
}
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.2",
"jest": "^29.3.1",
"nodemon": "^2.0.20",
"onchange": "^7.1.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
},
"dependencies": {
"@sapphire/framework": "^3.1.4",
"discord.js": "^13.12.0"
}
}
Favna
Favna3y ago
idk man. dump code on gh or something,.
McDefault
McDefaultOP3y ago
Ehh ima ditch this framework 🚀 Ill check back in few months to see if it will improve ty for the help anyways
Favna
Favna3y ago
this issue is not even related to the framework but sure bye i guess
Sawako
Sawako3y ago
._.
vladdy
vladdy3y ago
I hate to say it but this isn't an issue in the framework... Without a reproduction sample we cannot help. When in doubt, if you have clashing versions, nuke package-lock and node_modules and reinstall deps
McDefault
McDefaultOP3y ago
I doubt thats the case, I did all the updates and dedupe If you want, you can toss a package.json to me Docs should def. be updated for new people not known to the fw
Favna
Favna3y ago
we have a guide, we have a cli to generate a production ready example bot, we have many examples, we have many other bots using the fw. What more do you want. Did you even read the guide for starters.
McDefault
McDefaultOP3y ago
that sounds promising using CLI helped thanks for the tip awesome docker implementation too, kudos
Want results from more Discord servers?
Add your server