S-IAF
Join ServerSapphire - Imagine a framework
sapphire-support
bot won't get on and connect to discord.
PPsyonix_3/6/2023
hi, my bot won't turn on. i've coded a lot of bots before with sapphire and they worked just fine, decided to make a new project, coded the structure and everything good but when i run my
it just won't turn on.
"yarn watch:start"
- "watch:start": "tsc-watch --onSuccess \"node ./dist/index.js\""
it just won't turn on.

AOAnswer Overflow3/6/2023
SSpinel3/6/2023
PPsyonix_3/6/2023
@Favna should i show you my extended client's code or?
FFavna3/6/2023
sure more info is always better
SSpinel3/6/2023
When asking for help, make sure to provide as much detail as possible. What have you tried so far? Do you have stacktraces that you can show us? What are you trying to achieve? Try to answer these questions and others, so we do not have to ask for them afterwards.
❯ For a good guide on how to ask questions, see [the instructions that StackOverflow gives](https://stackoverflow.com/help/how-to-ask). You should try to always follow these guidelines.
❯ For an excellent video that shows how not to ask technical questions is this, watch [this YouTube video by LiveOverflow](https://youtu.be/53zkBvL4ZB4).
❯ [Asking technical questions (Clarkson)](https://www.cs.cornell.edu/courses/cs3110/2017fa/thoughtful.html)
❯ [How to ask questions the smart way (Raymond)](http://www.catb.org/~esr/faqs/smart-questions.html)
PPsyonix_3/6/2023
Bot.ts
PPsyonix_3/6/2023
import { LogLevel, SapphireClient } from '@sapphire/framework';
import { Partials } from 'discord.js';
export class Bot extends SapphireClient {
public botOwner = ['510866456708382730'];
public constructor() {
super({
caseInsensitiveCommands: true,
loadDefaultErrorListeners: true,
loadMessageCommandListeners: true,
regexPrefix: /^(hey +)?bot[,! ]/i,
logger: {
level: LogLevel.Debug,
},
partials: [Partials.Channel, Partials.Reaction, Partials.Message],
shards: 'auto',
intents: ['Guilds', 'GuildMembers', 'GuildMessages', 'DirectMessages'],
allowedMentions: {
repliedUser: true,
},
ws: {
properties: {
browser: 'Discord Android',
},
},
});
}
private connect() {
this.login();
}
private main() {
try {
this.connect();
} catch (e) {
this.logger.fatal(e);
process.exit(1);
}
}
public run() {
this.main();
}
}
PPsyonix_3/6/2023
this.login()
cause i use .env
PPsyonix_3/6/2023
which is inside the
src
folderFFavna3/6/2023
you don't have any
super.login()
FFavna3/6/2023
and having env in src is not a reason to have any of that. Look at some of the example bots:
FFavna3/6/2023
@Dragonite, @Gemboard for example
FFavna3/6/2023
in fact I see no reason at all to have a custom client there
FFavna3/6/2023
// Unless explicitly defined, set NODE_ENV as development:
process.env.NODE_ENV ??= 'development';
import { LogLevel, SapphireClient } from '@sapphire/framework';
import { getRootData } from '@sapphire/pieces';
import { GatewayIntentBits, Partials } from 'discord.js';
import { setup } from '@skyra/env-utilities';
import { join } from 'node:path';
async function main() {
setup(join('.env', getRootData().root));
const client = new SapphireClient({
caseInsensitiveCommands: true,
loadDefaultErrorListeners: true,
loadMessageCommandListeners: true,
regexPrefix: /^(hey +)?bot[,! ]/i,
logger: {
level: LogLevel.Debug
},
partials: [Partials.Channel, Partials.Reaction, Partials.Message],
shards: 'auto',
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages],
allowedMentions: {
repliedUser: true
},
ws: {
properties: {
browser: 'Discord Android'
}
}
});
try {
await client.login();
} catch (error) {
client.logger.fatal(error);
client.destroy();
process.exit(1);
}
}
void main();
Exact same code, but without completely unnecessary extended client
FFavna3/6/2023
Also it should be noted that you didn't add the
Message Content
intent... so yaknow... before you write message commands and you need to make another post saying they dont work.PPsyonix_3/6/2023
@Favna what do you mean lol, i want to build a bot with custom stuff, that's why i extended
SapphireClient
FFavna3/6/2023
you dont have custom stuff there
FFavna3/6/2023
and any custom properties you need can be defined outside of the client scope
FFavna3/6/2023
i.e. on the container scope
PPsyonix_3/6/2023
i've got
./lib/setup.ts
fileFFavna3/6/2023
why would you subject yourself to
container.client.customProperty
instead of container.customProperty
PPsyonix_3/6/2023
well not yet
PPsyonix_3/6/2023
my
setup.ts
file is this @Favna :// Unless explicitly defined, set NODE_ENV as development:
process.env.NODE_ENV ??= 'development';
import 'reflect-metadata';
import '@sapphire/plugin-logger/register';
import '@sapphire/plugin-api/register';
import '@sapphire/plugin-editable-commands/register';
import { config } from 'dotenv-cra';
import * as colorette from 'colorette';
import { inspect } from 'util';
import { join } from 'path';
import { srcDir } from './constants';
config({ path: join(srcDir, '.env') });
// Set default inspection depth
inspect.defaultOptions.depth = 1;
// Enable colorette
colorette.createColors({ useColor: true });
PPsyonix_3/6/2023
i prefer creating my own extended client, it's not about that
FFavna3/6/2023
well then you also fix your own issues :) :) :)
PPsyonix_3/6/2023
i've got
this.login()
FFavna3/6/2023
last I checked
this
is not the same as super
FFavna3/6/2023
but maybe my dictionary is wrong
PPsyonix_3/6/2023
uh
PPsyonix_3/6/2023
should i change
this
to super
?FFavna3/6/2023
sorry to be a bit of an asshole about it but if you want to ignore my recommendations then I don't see much reason to provide proper help either
PPsyonix_3/6/2023
no i am not ignoring
PPsyonix_3/6/2023
yo again, it does log into discord bot seems like my
ready.ts
isn't loadingPPsyonix_3/6/2023
nor any of my listeners
PPsyonix_3/6/2023
don't know what i doing wrong tbh
FFavna3/6/2023
did you read the big red block at the start of the guide: https://www.sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire
PPsyonix_3/6/2023
cool, it works
PPsyonix_3/6/2023
thanks man!
PPsyonix_3/6/2023
got question
PPsyonix_3/6/2023
what are
interaction-handlers
and how can i use those?FFavna3/6/2023
PPsyonix_3/6/2023
do i still have to use eg:
registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand(
{
name: "ping",
description: `Gets my ping to the Discord API and interaction round-trip.`,
},
{
guildIds: ["955500329489797180"],
idHints: ["968221223123316777"],
behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
}
);
}
}
@Favna ?PPsyonix_3/6/2023
and
chatInputRun()
?PPsyonix_3/6/2023
or there are any other methods?
FFavna3/6/2023
read our guide
PPsyonix_3/6/2023
okay
PPsyonix_3/6/2023
this 1?
FFavna3/6/2023
we didnt write it for it to be ignored smh
PPsyonix_3/6/2023
yep i know
FFavna3/6/2023
How about you try to find it yourself for ac hange
FFavna3/6/2023
instead of asking to be spoonfed links
PPsyonix_3/6/2023
there are many guides, just asked if you could point out which one to read lol
FFavna3/6/2023
there aren't many guides. There is one guide. With pages that you can navigate by clicking on them with your mouse cursor.
FFavna3/6/2023
I assume you have a mouse cursor
FFavna3/6/2023
it was invented in 1967 after all
PPsyonix_3/6/2023
dude it's fine, i'll just go through it
PPsyonix_3/6/2023
rofl