#API ERROR, UNKOWN MESSAGE V13

1 messages · Page 1 of 1 (latest)

keen turtle
#

This is the code before I edit it when I edit it I got an api error and didn't send the message to created room I want Someone to edit it with 7 seconds not args and automaticlly send the embed message in created room

client.on('messageCreate', async message => {
  let msg = message.content.split(' ');
  let command = msg[0].toLowerCase();
  let args = msg.slice(1);

  if (command === "count") {
    const i = args.join(" ");

    let count = i;

    const m = new Discord.MessageEmbed().setTitle(`${count}`);
    message.channel.send({embeds: [m]}).then(mes => {;
      const counter = setInterval(async function(){
        if (count >= 0) {
          m.setTitle(`${count}`)
          count--;
          mes.edit({embeds: [m]}).catch(console.log);
        } else {
          clearInterval(counter);
        }
      }, 1000);
    }).catch(console.log);
  }
})
supple sierra
#

count-- won't work because count is a string

keen turtle
#

hmm what I can do

supple sierra
#

you can to ```js
let count = Number(i);

BUT! Ensure that `i` is a number. If `i` is not a number count will be `NaN`
keen turtle
#
const i = 7;

let count = Number(i);
#

like this ?

supple sierra
#

no, in this case i is already a number. I assume you want to grab the arguments of the commands and then send an embed with the title of that arguments?

keen turtle
#

I can delete args now because I put i 7 seconds true ?

supple sierra
#

yes, in this case args is not needed

keen turtle
#

ok I want it to send the embed automaticly when the channel created without command

#

I try it like this

#

add .then((ch) => { after message create guild

#

and delete

client.on('message', async message => {
let msg = message.content.split(' ');
let command = msg[0].toLowerCase();
let args = msg.slice(1);

if (command === "count") {
const i = args.join(" ");
#

still

#
    const i = 7;

    let count = i;

    const m = new Discord.MessageEmbed().setTitle(`${count}`);
    message.channel.send({embeds: [m]}).then(mes => {;
      const counter = setInterval(async function(){
        if (count >= 0) {
          m.setTitle(`${count}`)
          count--;
          mes.edit({embeds: [m]}).catch(console.log);
        } else {
          clearInterval(counter);
        }
      }, 1000);
    }).catch(console.log);
  }
})
supple sierra
#

could you send your current code and the error please?

keen turtle
#

ok wait

#
const i = 7;
    let count = i;
message.guild.channels.create(`${args}`, { type: "text" })
.then((ch) => {
const m = new Discord.MessageEmbed().setTitle(`${count}`);
    ch.send({embeds: [m]}).then(mes => {;
      const counter = setInterval(async function(){
        if (count >= 0) {
          m.setTitle(`${count}`)
          count--;
          mes.edit({embeds: [m]}).catch(console.log);
        } else {
          clearInterval(counter);
        }
      }, 1000);
    }).catch(console.log);
  }
})
supple sierra
#

does the bot send the message with the embed?

keen turtle
#

no

#

I got an API error

supple sierra
#

that causes the error. If no message is sent the Unknown Message error occurs

supple sierra
keen turtle
supple sierra
#

lemme try it on my bot

keen turtle
#

ok I'm waiting you

supple sierra
#

which discord.js version do you use @keen turtle ?

keen turtle
#

13

supple sierra
#

use this code, yours includes some mistakes

message.guild.channels.create(`${args}`, {type: "GUILD_TEXT"})
            .then((ch) => {
                const m = new MessageEmbed().setTitle(`${count}`);
                ch.send({embeds: [m]}).then(mes => {
                    const counter = setInterval(async function(){
                        if (count >= 0) {
                            m.setTitle(`${count}`)
                            count--;
                            mes.edit({embeds: [m]}).catch(console.log);
                        } else {
                            clearInterval(counter);
                        }
                    }, 1000);
                }).catch(console.log);
            })}
keen turtle
#

ok wait

#

You try it in your bot ?

supple sierra
#

yes, it worked without problems

keen turtle
#

still the problem

supple sierra
#
import {Client, Intents, MessageEmbed} from "discord.js"
const client = new Client({
    intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS]
})

client.on("messageCreate", async (message) => {
    let msg = message.content.split(' ');
    let command = msg[0].toLowerCase();
    let args = msg.slice(1);

    if (command === "count") {
        const i = 7;

        let count = i;

        const m = new MessageEmbed().setTitle(`${count}`);
        message.guild?.channels.create(`${args}`, {type: "GUILD_TEXT"})
            .then((ch) => {
                const m = new MessageEmbed().setTitle(`${count}`);
                ch.send({embeds: [m]}).then(mes => {
                    const counter = setInterval(async function(){
                        if (count >= 0) {
                            m.setTitle(`${count}`)
                            count--;
                            mes.edit({embeds: [m]}).catch(console.log);
                        } else {
                            clearInterval(counter);
                        }
                    }, 1000);
                }).catch(console.log);
            })}
})

client.on("ready", () => console.log("Bot is ready"))

client.login("TOKEN")

That is the whole code I used (it's TypeScript so don't just copy paste it)

supple sierra
#

does your bot create a new text channel?

keen turtle
#

yes

supple sierra
#

but no message is sent into that new channel right?

keen turtle
#

yes

#

true

supple sierra
#

does your bot have enough permissions?

keen turtle
#

yes it has administrator

supple sierra
#

ok, that is weird. idk what causes the problem you experience, I cannot reproduce your error

keen turtle
#

FeelsBadMan ok no problem

#

@supple sierra Can I ask you another question ?

supple sierra
#

sure

keen turtle
#

How Can I make the bot after 1minute to make a thing in the new room
like : when the room created after 1 min the bot will do something like update permission of the room or like this

#

I want to use function setTimeout true ?

supple sierra
#

you can use the native setTimeout() function. Like ```js
const channel = message.guild.channels.create("name", {type: "GUILD_TEXT"})
setTimeout(async () => {
await channel.edit({
permissionOverwrites: [/* here you set the new permissions */]
}, 10000 /the milliseconds/)

keen turtle
#

oh

#

I will try it

#

ty ❤️

supple sierra
#

sorry, I made a mistake, that's the right code

const channel = await message.guild.channels.create("name", {type: "GUILD_TEXT"})
        setTimeout(async () => {
            await channel.edit({
                permissionOverwrites: [/* here you set the new permissions */]
            })
}, 10000)
keen turtle
#

nop

keen turtle
#

like this will work ?

#

or should I add const channel

#

okay I know now you put channel.edit so it should

supple sierra
#

which channel do you want to edit in the first line of the setTimeout() function (the channel.edit() function)?

keen turtle
#

yes yes I didn't see it

#

like this ?

supple sierra
#

yes

keen turtle