bot won't get on and connect to discord.

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 "yarn watch:start" - "watch:start": "tsc-watch --onSuccess \"node ./dist/index.js\"" it just won't turn on.
31 Replies
Psyonix_
Psyonix_OP2y ago
@Favna should i show you my extended client's code or?
Favna
Favna2y ago
sure more info is always better
Spinel
Spinel2y ago
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. 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. ❯ Asking technical questions (Clarkson)How to ask questions the smart way (Raymond)
Psyonix_
Psyonix_OP2y ago
Bot.ts
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();
}
}
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();
}
}
this.login() cause i use .env which is inside the src folder
Favna
Favna2y ago
you don't have any super.login() and having env in src is not a reason to have any of that. Look at some of the example bots: @Dragonite, @Gemboard for example in fact I see no reason at all to have a custom client there
// 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();
// 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 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.
Psyonix_
Psyonix_OP2y ago
@Favna what do you mean lol, i want to build a bot with custom stuff, that's why i extended SapphireClient
Favna
Favna2y ago
you dont have custom stuff there and any custom properties you need can be defined outside of the client scope i.e. on the container scope
Psyonix_
Psyonix_OP2y ago
i've got ./lib/setup.ts file
Favna
Favna2y ago
why would you subject yourself to container.client.customProperty instead of container.customProperty
Psyonix_
Psyonix_OP2y ago
well not yet 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 });
// 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 });
i prefer creating my own extended client, it's not about that
Favna
Favna2y ago
well then you also fix your own issues :) :) :)
Psyonix_
Psyonix_OP2y ago
i've got this.login()
Favna
Favna2y ago
last I checked this is not the same as super but maybe my dictionary is wrong
Psyonix_
Psyonix_OP2y ago
uh should i change this to super?
Favna
Favna2y ago
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
Psyonix_
Psyonix_OP2y ago
no i am not ignoring yo again, it does log into discord bot seems like my ready.ts isn't loading nor any of my listeners don't know what i doing wrong tbh
Favna
Favna2y ago
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
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
Psyonix_
Psyonix_OP2y ago
cool, it works thanks man! got question what are interaction-handlers and how can i use those?
Favna
Favna2y ago
Sapphire Framework
What are they? | Sapphire
These are interaction handlers! A simple class you can extend to handle almost all the interactions you may receive in
Favna
Favna2y ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
Favna
Favna2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Psyonix_
Psyonix_OP2y ago
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,
}
);
}
}
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 ? and chatInputRun()? or there are any other methods?
Favna
Favna2y ago
read our guide
Psyonix_
Psyonix_OP2y ago
okay this 1?
Favna
Favna2y ago
we didnt write it for it to be ignored smh
Psyonix_
Psyonix_OP2y ago
yep i know
Favna
Favna2y ago
How about you try to find it yourself for ac hange instead of asking to be spoonfed links
Psyonix_
Psyonix_OP2y ago
there are many guides, just asked if you could point out which one to read lol
Favna
Favna2y ago
there aren't many guides. There is one guide. With pages that you can navigate by clicking on them with your mouse cursor. I assume you have a mouse cursor it was invented in 1967 after all
Psyonix_
Psyonix_OP2y ago
dude it's fine, i'll just go through it rofl
Want results from more Discord servers?
Add your server