samp
samp
DIAdiscord.js - Imagine an app
Created by samp on 12/10/2023 in #djs-questions
Message doesn't send to channel
client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync(join(__dirname, 'messages.json'), 'utf8'));

// Get a random join message index
const randomIndex = Math.floor(Math.random() * jsonData.joinMessages.length);

// Get the random join message
const randomJoinMessage = jsonData.joinMessages[randomIndex];

console.log(randomJoinMessage);

// Insert the user's username into the join message
const formattedJoinMessage = randomJoinMessage.replace("{userName}", member.user.username);

console.log(formattedJoinMessage);

const channel = client.channels.cache.get('1174309146816950303'); // #new-beavers
if (channel && channel.type == ChannelType.GuildText) {
channel.send(formattedJoinMessage);
console.log ("message sent");
}
});
client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync(join(__dirname, 'messages.json'), 'utf8'));

// Get a random join message index
const randomIndex = Math.floor(Math.random() * jsonData.joinMessages.length);

// Get the random join message
const randomJoinMessage = jsonData.joinMessages[randomIndex];

console.log(randomJoinMessage);

// Insert the user's username into the join message
const formattedJoinMessage = randomJoinMessage.replace("{userName}", member.user.username);

console.log(formattedJoinMessage);

const channel = client.channels.cache.get('1174309146816950303'); // #new-beavers
if (channel && channel.type == ChannelType.GuildText) {
channel.send(formattedJoinMessage);
console.log ("message sent");
}
});
basically, all the log messages appear EXCEPT for message sent, and the message is not sent to the channel. the channel id is correct
12 replies
DIAdiscord.js - Imagine an app
Created by samp on 12/10/2023 in #djs-questions
Join messages don't want to work?
For some reason, it can't read "messages.json" because it's not valid directory...but it's right there?
client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync("messages.json", 'utf8'));

// Get a random join message index
const randomIndex = Math.floor(Math.random() * jsonData.joinMessages.length);

// Get the random join message
const randomJoinMessage = jsonData.joinMessages[randomIndex];

console.log(randomJoinMessage);

// Insert the user's username into the join message
const formattedJoinMessage = randomJoinMessage.replace("{userName}", member.user.username);

console.log(formattedJoinMessage);

const channel = client.channels.cache.get('1174309146816950303'); // #new-beavers
if (channel && channel.type == ChannelType.GuildText) {
channel.send(formattedJoinMessage);
console.log ("message sent");
}
});
client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync("messages.json", 'utf8'));

// Get a random join message index
const randomIndex = Math.floor(Math.random() * jsonData.joinMessages.length);

// Get the random join message
const randomJoinMessage = jsonData.joinMessages[randomIndex];

console.log(randomJoinMessage);

// Insert the user's username into the join message
const formattedJoinMessage = randomJoinMessage.replace("{userName}", member.user.username);

console.log(formattedJoinMessage);

const channel = client.channels.cache.get('1174309146816950303'); // #new-beavers
if (channel && channel.type == ChannelType.GuildText) {
channel.send(formattedJoinMessage);
console.log ("message sent");
}
});
8 replies
DIAdiscord.js - Imagine an app
Created by samp on 5/27/2023 in #djs-questions
Question relating to DMs
When users disable permissions for server members to DM them, when a bot tries to DM them, it produces an error. I can use a catch to prevent it from crashing, but is there any way to find out whether a user has server member DMs enabled, as I would like to notify the person sending the command that setting is disabled.
8 replies
DIAdiscord.js - Imagine an app
Created by samp on 4/2/2023 in #djs-questions
I'm using typescript, but my code has loads of errors.
The errors are as follow: [var] is possibly null (e.g. client.user is possible null) Property 'user' does not exist on type '[property X] | [property Y]'. Property 'user' does not exist on type '[property Y]'. (e.g. Property 'user' does not exist on type 'GuildMember | APIInteractionDataResolvedGuildMember'. Property 'user' does not exist on type 'APIInteractionDataResolvedGuildMember'.) Argument of type '[type 1]' is not assignable to parameter of type '[type 2]'. (e.g. Argument of type 'number' is not assignable to parameter of type 'string'.)
38 replies
DIAdiscord.js - Imagine an app
Created by samp on 3/11/2023 in #djs-questions
Make embeds smaller in any way
6 replies
DIAdiscord.js - Imagine an app
Created by samp on 2/25/2023 in #djs-questions
How to create commands with "alternative" names
For example, Arcane has /rank and /level, both of which do the same thing. Right now, I'm just having two identical commands, but I've already reached 100 commands and I need space for more. Is there any other way to do this?
13 replies
DIAdiscord.js - Imagine an app
Created by samp on 2/23/2023 in #djs-questions
How to have cooldown on commands based on conditions
Basically, I want a cooldown on the command if the user lost, but not if the user won(which would be a bool).
11 replies
DIAdiscord.js - Imagine an app
Created by samp on 1/12/2023 in #djs-questions
Can you find location of member? (v14.5.0)
I am trying to create a command which tries to detect whether you are in India or not.
10 replies
DIAdiscord.js - Imagine an app
Created by samp on 11/27/2022 in #djs-questions
Discord Bot Command IDEAS
Sup! I'm making a discord bot using Discord.js v14.5.0, and I need help on what commands I should make!
7 replies
DIAdiscord.js - Imagine an app
Created by samp on 10/3/2022 in #djs-questions
TimeStamp slash command v14.5.0
How's it going everyone? Right now, I'm making a discord bot that has basic utility commands and some fun ones too! I think it would be pretty damn useful for my bot to be able to convert a time(with an integer output of hour, minute, etc.) into a formatter timestamp (like this website does https://hammertime.cyou/). Does anyone know how to do this? I can't find it online.
15 replies
DIAdiscord.js - Imagine an app
Created by samp on 10/2/2022 in #djs-questions
Role checking user does not work
12 replies
DIAdiscord.js - Imagine an app
Created by samp on 10/2/2022 in #djs-questions
Check if user has a role
Hey guys! I'm wondering how you would check if a user has a specific role. Basically, I'm programming a game of tag and I'm using a role to track who is it(so it is clear whether you are it or not). I've seen people check permissions, but this role won't have any, and I have other roles which don't have perms as well. Can you please help?
29 replies