K
K
Kurooooo2020-07-29 02:16:18
Node.js
Kurooooo, 2020-07-29 02:16:18

I work with the DiscordJS library, I need to make the bot send messages without an event, how to do it?

I am making a discord bot and I really need to make it so that the bot just takes and sends messages (for example, when some time passes or sending a message will be in another function), you need to bypass event tracking, here is an example code

async function sender(bot, message, args) {
    if (brandshopp.type == '1') {
        let embed = new Discord.MessageEmbed().setTitle(brandshopp.model)
            .addField('**Тип релиза:**', '**Анонс**')
            .addField('**Бренд**', brandshopp.name)
            .setThumbnail(brandshopp.photo)
            .addField('**Модель**', brandshopp.model)
            .addField('**Useful Links**', '[Новинки](https://brandshop.ru/new/) | [Login](https://brandshop.ru/login/) | [Checkout ](https://brandshop.ru/checkout/)')
            .setFooter(`${ brandshopp.time } куро`)
            .setColor(0x32d160)
        await message.channels.cache.get("тут айди канала").send(embed)
            // bot.on('ready', () => {
            //     bot.channels.cache.get("тут айди канала").send(embed)
            // })
    }
}

sender(bot)


if you use bot.on('ready', () => {bot.channels.cache.get("channel id here").send(embed)} then it is logical that it only works when the bot starts, but I need could call the sender function, always

this is the error it gives
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channel' of undefined

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Megum1n, 2020-07-29
@Megum1n

Send a message anywhere in the program:

var server = "server_id"
var channel = "channel_id"
client.guilds.get(server).channels.get(channel).send("text");

V
Vlad Morkovkin, 2021-08-14
@Vlad808

All discord.js is command based. Therefore, this makes no sense. Of course, you can track the text in the console, but this will not be a discord bot at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question