discord.js random image question

Asked 2 years ago, Updated 2 years ago, 73 views

// Send hikari's image
client.on('message', message => {
    if (message.content.startsWith ("hikari")) {
        const hikari = [
            'https://example/giphy.gif',
            'https://example/giphy2.gif',
            'https://example/giphy3.gif',
            ]


            message.channel.send({
                file: hikari[Math.floor(Math.random() * hikari.length)]
            });

    }
});

If you type hikari after this,

(node:12432) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\local address\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:12432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12432) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I can't load it with this error.

message.channel.send({
                file: hikari[Math.floor(Math.random() * hikari.length)]
            });

I think there's a problem with that, but I'm not good enough to fix it ㅠ<

node.js image random

2022-09-20 22:03

1 Answers

message.channel.send({
    files: [hikari[Math.floor(Math.random() * hikari.length)]]
});

I think I can do it like this

Reference site


2022-09-20 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.