mizorint
mizorint
Explore posts from servers
SIASapphire - Imagine a framework
Created by mizorint on 8/30/2024 in #sapphire-support
How do I make my bot "greet" a new member?
So I have this projeect structure.
src/
commands/
ping.js - WORKING command
listeners/
guildAddMember.js - the file I work on the welcome message in
index.js
package.json
src/
commands/
ping.js - WORKING command
listeners/
guildAddMember.js - the file I work on the welcome message in
index.js
package.json
The code of guildAddMember.js file:
const { Listener } = require('@sapphire/framework');
const { Embed, EmbedBuilder } = require('discord.js');

class WelcomeListener extends Listener {
constructor(context, options) {
super(context, {
...options,
event: 'guildMemberAdd'
});
}

async run(member) {
const { client } = this.container;

const newcomer = this.container.guild.member;
const channel = client.channels.cache.get('channel id IS provided and is correct');

const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(`Welcome, ${newcomer}`)
.setDescription('We\'re glad you joined us.')
.setTimestamp()

channel.send({ embeds: [embed] });
}
}

module.exports = {
WelcomeListener
};
const { Listener } = require('@sapphire/framework');
const { Embed, EmbedBuilder } = require('discord.js');

class WelcomeListener extends Listener {
constructor(context, options) {
super(context, {
...options,
event: 'guildMemberAdd'
});
}

async run(member) {
const { client } = this.container;

const newcomer = this.container.guild.member;
const channel = client.channels.cache.get('channel id IS provided and is correct');

const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(`Welcome, ${newcomer}`)
.setDescription('We\'re glad you joined us.')
.setTimestamp()

channel.send({ embeds: [embed] });
}
}

module.exports = {
WelcomeListener
};
index.js file:
const { SapphireClient } = require('@sapphire/framework');
const { GatewayIntentBits} = require('discord.js');
const { token } = require('../config.json');
const colors = require('colors');

const client = new SapphireClient({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],

loadMessageCommandListeners: true,
});

client.login(token).then((token) =>
client.user.setPresence({ activities: [{ name: 'with your mind' }], status: 'online' })
);
const { SapphireClient } = require('@sapphire/framework');
const { GatewayIntentBits} = require('discord.js');
const { token } = require('../config.json');
const colors = require('colors');

const client = new SapphireClient({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],

loadMessageCommandListeners: true,
});

client.login(token).then((token) =>
client.user.setPresence({ activities: [{ name: 'with your mind' }], status: 'online' })
);
For some reason, when I join with my alt, the bot does not react with any message. I need help finding out why, thanks!
21 replies
DIAdiscord.js - Imagine an app
Created by mizorint on 6/20/2024 in #djs-questions
Code organisation
Does discord.js have a feature like Composer in Telegraf (the library to make Telegram bots)? I don't think so (or at least I don't know). It would be cool to have such a feature that helps organising code into files without implementing command and/or event handlers. Please let me know if there is something like that by tagging me, thanks!
8 replies