#text message to channel

1 messages · Page 1 of 1 (latest)

quick halo
#

I'm a beginner, want to send a text message to specific channel, here's how im doing it right now:

const channel = client.channels.cache.get(id);

if (channel?.isTextBased()) {
  channel.send('My Message');
}
sly agate
#

yes? what do you need help with

#

also dont really think creating a thread is neccesary

quick halo
#

Hi, it's weird, I execute it and shows no errors, but message doesnt go through. Why not, otherwise i will litter the chat

#

the only permission bot has is "send messages"

#

is it enough? connects with no problem

sly agate
#

do you have the right intents, and is your bot able to actually view the channel

quick halo
#

im not sure, i assume you mean scopes and permissions, of which it has these:

sly agate
#

no, intents. show your client constructor

#

also, send messages =/= view channels

quick halo
#

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

#

this one right?

versed roverBOT
sly agate
#

you are missing a lot of intents

quick halo
#

I've added

        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
    ],
#

would that be enough?

sly agate
#

i guess so, depends on what you plan to do

#

enable them in the dev portal too

quick halo
#

compiler throws error: used disallowed intents..

sly agate
quick halo
sly agate
#

not permission, intents

#

intents =/= permissions

quick halo
#

oh im starting to understand

#

where can i find intentions in the dev portal

#

u mean this place right

sly agate
#

bot

#

the bot tab

quick halo
#

damn...

#

do i have to do anything with permissions integer?

sly agate
#

no

#

that just gets generated based on the permissions you select

quick halo
#
// Require the necessary discord.js classes
import { Client, Events, GatewayIntentBits } from 'discord.js';
const token = '';

// Create a new client instance
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers
    ]
});

const channel = await client.channels.cache.get('');

// Log in to Discord with your client's token
client.login(token);

// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, (c) => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
    if (channel?.isTextBased()) {
        channel.send('My Message');
    }
});
sly agate
#

there's multiple things wrong here

#

first of all, i hope you use an actual token an channel id, second: you try to access a channel before the client is logged in, third you dont need to await when you use .cache