discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.3k stars 3.96k forks source link

Issue with sending DM #9494

Closed jdmartin closed 1 year ago

jdmartin commented 1 year ago

Which package is this bug report for?

discord.js

Issue description

  1. I am using discord.js on Node.js v18.16.0.
  2. I have a command that takes interaction input via /attendance, and then starts communicating with that user via DM.
  3. When I execute that command, I get this error:
/home/dev/speedybot/node_modules/discord.js/src/structures/MessagePayload.js:202
        isJSONEncodable(embed) ? embed.toJSON() : this.target.client.options.jsonTransformer(embed),
        ^
TypeError: isJSONEncodable is not a function
    at /home/dev/speedybot/node_modules/discord.js/src/structures/MessagePayload.js:202:9
    at Array.map (<anonymous>)
    at MessagePayload.resolveBody (/home/dev/speedybot/node_modules/discord.js/src/structures/MessagePayload.js:201:36)
    at DMChannel.send (/home/dev/speedybot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:158:61)
    at MessageCollector.<anonymous> (/home/dev/speedybot/slash-commands/attendance.js:46:32)
    at MessageCollector.emit (node:events:513:28)
    at MessageCollector.handleCollect (/home/dev/speedybot/node_modules/discord.js/src/structures/interfaces/Collector.js:133:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

As far as I can tell, this is the relevant section of my (probably janky) code that executes before the error occurs. This had been working fine for months before the update to 14.10.1

I hope this is enough to get things started. Please do let me know if I missed a key detail, and I'll get right on it. Thanks, as always, for discord.js. ❤️

Code sample

const { SlashCommandBuilder } = require("@discordjs/builders");

const absence = require("../db/absencedb-slash.js");
const absenceDBHelper = new absence.DataDisplayTools();

const attendanceTools = require("../utils/attendance-utils.js");
const attendanceHelper = new attendanceTools.attendanceTools();

const utils = require("../utils/speedyutils.js");
const client = utils.client;

module.exports = {
    data: new SlashCommandBuilder().setName("attendance").setDescription("Manage your raid attendance!"),

    async execute(interaction) {
        interaction.reply({
            content: "Ok, check your DMs and we'll do this.",
            ephemeral: true,
        });

        const user = client.users.cache.get(interaction.member.user.id);

        const name = interaction.user.username;

        const DM = await interaction.user.send({
            content: `Please choose the number that corresponds to what you want to do.\n  \n\t1. **Show/Cancel** Existing Entries\n\t2. Say You'll Be **Absent** or **Late**...\n\tQ. **Quit**`,
        });

        const collector = DM.channel.createMessageCollector({
            time: 30000,
        });

        var response = "";

        collector.on("collect", (m) => {
        ...

Versions

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Channel, Message, Reaction

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildWebhooks, GuildPresences, GuildMessages, GuildMessageReactions, DirectMessages, DirectMessageReactions, DirectMessageTyping, MessageContent

I have tested this issue on a development release

No response

brn-hyn commented 1 year ago

Having the same issue as well TypeError: isJSONEncodable is not a function after updating from 14.9.0 to 14.10.1