WhacK
WhacK
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by WhacK on 3/7/2024 in #djs-questions
reply to message with channel webhook
It also accepts a MessagePayload so I thought it might be possible but I'll have to go back to copying the prior content and appending with markdown
10 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 3/7/2024 in #djs-questions
reply to message with channel webhook
No description
10 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 3/7/2024 in #djs-questions
reply to message with channel webhook
beholder@8.3.0 /Users/sr/Engrimoore/Beholder └── discord.js@14.14.1 -> % node -v v18.18.2
10 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
thank you
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
ok that's why all the examples read as accessing them. I thought I was being clever
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
I didn't realize that was mutating it but now that you say that it make sense. Trying teach myself how to do this
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
so if I do message.embeds[0] it should stop soing that?
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
I use the sapphire framework
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
export const CLIENT_OPTIONS: ClientOptions = {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
allowedMentions: { users: [], roles: [] },
presence: {
activities: [{ name: 'over Engrimoore!', type: ActivityType.Watching }]
},
defaultPrefix: PREFIX,
disableMentionPrefix: true,
caseInsensitiveCommands: true,
logger: { level: PROD ? LogLevel.Info : LogLevel.Debug },
partials: [Partials.Channel],
loadMessageCommandListeners: true,
tasks: {
bull: {
connection: { ...parseRedisOptions() , db: envParseInteger('REDIS_DB')},
}
}
// sweepers: {
// ...Options.defaultSweeperSettings,
// messages: {
// interval: minutes.toSeconds(3),
// lifetime: minutes.toSeconds(15)
// }
// }
};
export const CLIENT_OPTIONS: ClientOptions = {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
allowedMentions: { users: [], roles: [] },
presence: {
activities: [{ name: 'over Engrimoore!', type: ActivityType.Watching }]
},
defaultPrefix: PREFIX,
disableMentionPrefix: true,
caseInsensitiveCommands: true,
logger: { level: PROD ? LogLevel.Info : LogLevel.Debug },
partials: [Partials.Channel],
loadMessageCommandListeners: true,
tasks: {
bull: {
connection: { ...parseRedisOptions() , db: envParseInteger('REDIS_DB')},
}
}
// sweepers: {
// ...Options.defaultSweeperSettings,
// messages: {
// interval: minutes.toSeconds(3),
// lifetime: minutes.toSeconds(15)
// }
// }
};
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
Yes
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
not edited
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
ok let me double check rn
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
I'm thinking it may edit it because that might be why sometimes they are there and sometimes not
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
my bot is only for running my d&d westmarch not made for all servers
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
Is the Avrae D&D bot. It takes a commands !rollstats and generates an embed with the array of stats
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
I didn't know that about channels I'll change that back originally I didn't fetch changed that last night
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
I hard code the ID in my database, I am definitely getting the right message just sometime embeds are there and sometimes not
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
Get messageId from discord link:
export async function fetchMessageByLink(messageLink: string) {
const [guildId, channelId, messageId] = messageLink.split('/');
const { client, _config } = container;

if (guildId !== _config.guildId) {
return Promise.reject('This can only be used in Engrimoore');
}

const channel = await client.guilds.cache
.get(guildId)
.channels.fetch(channelId)
.catch((e) => Promise.reject(e));

if (channel.isTextBased()) {
const message = await channel.messages.fetch(messageId).catch((e) => Promise.reject(e));

if (isNullish(message)) {
return Promise.reject('Unable to fetch message by url');
}
return message;
}

return Promise.reject('Must be run in an Engrimoore Text Channel.');
}
export async function fetchMessageByLink(messageLink: string) {
const [guildId, channelId, messageId] = messageLink.split('/');
const { client, _config } = container;

if (guildId !== _config.guildId) {
return Promise.reject('This can only be used in Engrimoore');
}

const channel = await client.guilds.cache
.get(guildId)
.channels.fetch(channelId)
.catch((e) => Promise.reject(e));

if (channel.isTextBased()) {
const message = await channel.messages.fetch(messageId).catch((e) => Promise.reject(e));

if (isNullish(message)) {
return Promise.reject('Unable to fetch message by url');
}
return message;
}

return Promise.reject('Must be run in an Engrimoore Text Channel.');
}
26 replies
DIAdiscord.js - Imagine an app
Created by WhacK on 9/18/2023 in #djs-questions
Channel.messages.fetch(id) giving mixed results
Slash Command:
public async chatInputSubmitCharacter(interaction: Command.ChatInputCommandInteraction) {
if (interaction.user.bot) return;
await interaction.deferReply({ ephemeral: true });

try {
const { options: args, channel: intChannel, user, guild } = interaction;
const channel = <TextChannel>guild.channels.cache.get(this.characterApprovalChannelId);
const statChannel = <TextChannel>guild.channels.cache.get(this.statRollChannelId);

const sheetUrl = args.getString('sheeturl');
if (isNullish(sheetUrl)) {
throw new Error('Please enter an sheet url to import');
}

//attempt to get ddb data from provided url
const urlSections = sheetUrl.split('/').reverse();
let raw: IBeyondData;
for (let section of urlSections) {
if (section && isNumber(section)) {
try {
raw = (await getBeyondData(section)).data;
} catch (error) {
throw new Error('Error trying to get DDB sheet:' + error.message);
}
}
}

if (raw === null) {
throw new Error('Unable to extract sheet information, please provide a public link.');
}

if (isNullishOrEmpty(raw.inventory)) {
throw new Error('Please complete your character inventory.');
}

let statRollMsg: Message<boolean>;
if (raw.configuration.abilityScoreType === StatGenerationMethodEnum.RolledStats) {
statRollMsg = await fetchMessageByLink(args.getString('staturl')).catch((e) =>
Promise.reject(`Please enter the link to the correct message in <#${this.statRollChannelId}>`)
);
}

const charData = await container.character.parseCharacterData(raw);

const reviewedData = container.character.reviewStatConformity(
raw.configuration.abilityScoreType,
charData,
isNullishOrEmpty(statRollMsg) ? null : statRollMsg.embeds.pop().fields
);

const submissionEmbed = await container.character.createApprovalEmbed(interaction, reviewedData, raw);

const approvalRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(`${CharaterCustomIds.Approve}_${interaction.user.id}_${charData.id}`)
.setStyle(ButtonStyle.Success)
.setLabel('Approve'),
new ButtonBuilder()
.setCustomId(`${CharaterCustomIds.Reject}_${interaction.user.id}_${charData.id}`)
.setStyle(ButtonStyle.Danger)
.setLabel('Reject')
);

await channel.send({
content: `Hey ${guild.roles.cache.get(AdminRoles.VANGUARD_ROLE)} and ${guild.roles.cache.get(AdminRoles.WARDEN_ROLE)}`,
embeds: [submissionEmbed],
components: [approvalRow]
});

const cached = await container.redis.insert(RedisKeys.Submission, `${interaction.user.id}:${charData.id}`, raw);
if (!cached) {
throw new Error('Unable to save submission.');
}

return interaction.editReply("Thanks! You're submission has been submitted. You will be notified upon review.");
} catch (error: any) {
console.error(error);
return interaction.reply({
content: error.message || 'An unexpected error occurred. If the problem persists, please contact a Code Weaver.',
ephemeral: true
});
}
}
public async chatInputSubmitCharacter(interaction: Command.ChatInputCommandInteraction) {
if (interaction.user.bot) return;
await interaction.deferReply({ ephemeral: true });

try {
const { options: args, channel: intChannel, user, guild } = interaction;
const channel = <TextChannel>guild.channels.cache.get(this.characterApprovalChannelId);
const statChannel = <TextChannel>guild.channels.cache.get(this.statRollChannelId);

const sheetUrl = args.getString('sheeturl');
if (isNullish(sheetUrl)) {
throw new Error('Please enter an sheet url to import');
}

//attempt to get ddb data from provided url
const urlSections = sheetUrl.split('/').reverse();
let raw: IBeyondData;
for (let section of urlSections) {
if (section && isNumber(section)) {
try {
raw = (await getBeyondData(section)).data;
} catch (error) {
throw new Error('Error trying to get DDB sheet:' + error.message);
}
}
}

if (raw === null) {
throw new Error('Unable to extract sheet information, please provide a public link.');
}

if (isNullishOrEmpty(raw.inventory)) {
throw new Error('Please complete your character inventory.');
}

let statRollMsg: Message<boolean>;
if (raw.configuration.abilityScoreType === StatGenerationMethodEnum.RolledStats) {
statRollMsg = await fetchMessageByLink(args.getString('staturl')).catch((e) =>
Promise.reject(`Please enter the link to the correct message in <#${this.statRollChannelId}>`)
);
}

const charData = await container.character.parseCharacterData(raw);

const reviewedData = container.character.reviewStatConformity(
raw.configuration.abilityScoreType,
charData,
isNullishOrEmpty(statRollMsg) ? null : statRollMsg.embeds.pop().fields
);

const submissionEmbed = await container.character.createApprovalEmbed(interaction, reviewedData, raw);

const approvalRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(`${CharaterCustomIds.Approve}_${interaction.user.id}_${charData.id}`)
.setStyle(ButtonStyle.Success)
.setLabel('Approve'),
new ButtonBuilder()
.setCustomId(`${CharaterCustomIds.Reject}_${interaction.user.id}_${charData.id}`)
.setStyle(ButtonStyle.Danger)
.setLabel('Reject')
);

await channel.send({
content: `Hey ${guild.roles.cache.get(AdminRoles.VANGUARD_ROLE)} and ${guild.roles.cache.get(AdminRoles.WARDEN_ROLE)}`,
embeds: [submissionEmbed],
components: [approvalRow]
});

const cached = await container.redis.insert(RedisKeys.Submission, `${interaction.user.id}:${charData.id}`, raw);
if (!cached) {
throw new Error('Unable to save submission.');
}

return interaction.editReply("Thanks! You're submission has been submitted. You will be notified upon review.");
} catch (error: any) {
console.error(error);
return interaction.reply({
content: error.message || 'An unexpected error occurred. If the problem persists, please contact a Code Weaver.',
ephemeral: true
});
}
}
26 replies