message.content isn't working with any of the commands I made. It doesn't see my message's content. It's only working when I use message.content === ""
My code:
const Discord = require('discord.js');
const { Client, Intents, Collection } = require('discord.js')
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", (message) => {
if(message.content === ""){
message.reply("I am working");
}
});
client.login("..");
I have recently spent a long time making a discord ticket bot, and all of a sudden now, it isnt turning on. There are no error messages when I turn the bot on, and the webview says the bot is online. I am hosting on repl.it
Sorry for the long code, but any genius who could work this out would be greatly appreciated. Thanks in advance.
const fs = require('fs');
const client = new Discord.Client();
const prefix = '-'
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`./commands/${file}`)
client.commands.set(command.name, command);
}
require('./server.js')
client.on("ready", () => {
console.log('Bot ready!');
client.user.setActivity('-help', { type: "LISTENING"} ).catch(console.error)
})
client.on("message", async (message) => {
if (message.author.bot) return;
const filter = (m) => m.author.id === message.author.id;
if (message.content === "-ticket") {
let channel = message.author.dmChannel;
if (!channel) channel = await message.author.createDM();
let embed = new Discord.MessageEmbed();
embed.setTitle('Open a Ticket')
embed.setDescription('Thank you for reaching out to us. If you have a question, please state it below so I can connect you to a member of our support team. If you a reporting a user, please describe your report in detail below.')
embed.setColor('AQUA')
message.author.send(embed);
channel
.awaitMessages(filter, {max: 1, time: 1000 * 300, errors: ['time'] })
.then ( async (collected) => {
const msg = collected.first();
message.author.send(`
>>> β
Thank you for reaching out to us! I have created a case for your inquiry with out support team. Expect a reply soon!
β Your question: ${msg}
`);
let claimEmbed = new Discord.MessageEmbed();
claimEmbed.setTitle('New Ticket')
claimEmbed.setDescription(`
New ticket created by ${message.author.tag}: ${msg}
React with β
to claim!
`)
claimEmbed.setColor('AQUA')
claimEmbed.setTimestamp()
try {
let claimChannel = client.channels.cache.find(
(channel) => channel.name === 'general',
);
let claimMessage = await claimChannel.send(claimEmbed);
claimMessage.react('β
');
const handleReaction = (reaction, user) => {
if (user.id === '923956860682399806') {
return;
}
const name = `ticket-${user.tag}`
claimMessage.guild.channels
.create(name, {
type: 'text',
}).then(channel => {
console.log(channel)
})
claimMessage.delete();
}
client.on('messageReactionAdd', (reaction, user) => {
const channelID = '858428421683675169'
if (reaction.message.channel.id === channelID) {
handleReaction(reaction, user)
}
})
} catch (err) {
throw err;
}
})
.catch((err) => console.log(err));
}
})
client.login(process.env['TOKEN'])
Your problem could possibly be that you have not put any intents. Intents look like this:
const { Client } = require('discord.js');
const client = new Client({
intents: 46687,
});
You can always calculate your intents with this intents calculator: https://ziad87.net/intents/
Side note:
If you are using discord.js v14 you change client.on from message to messageCreate.
I included Emoji For Button In My Code IDK The Reason It Crashes Can Someone Say Me The Solution
I Searched Internet And Also Another Stackoverflow Discussion But Didn't Found A Fix
IDK WHAT TO SAY MORE ---------------------------------------------------------------------------------------------------------------------------------------------------------------
import { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setActivity(`>>rank`, { type: "WATCHING" });
});
client.on("messageCreate", (message) => {
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
const btn2 = new ButtonBuilder()
.setLabel('YT')
.setEmoji("<1008747826714521610>")
.setStyle('Link')
.setURL('https://www.youtube.com/c/himisa')
const btn3 = new ButtonBuilder()
.setCustomId('btn2')
.setLabel('Click Me!')
.setStyle('Success')
if (message.content === 'hi'){
return message.channel.send({
content: 'HI' , components:[new ActionRowBuilder().addComponents(btn1,btn2,btn3)]
})
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
await interaction.channel.send('Um Hello');
}
}
});
client.login('SUPER SECRET TOKEN');
You're only supposed to put the emoji ID there, remove the < > and it should work.
.setEmoji("1008747826714521610")
Source: The official discord.js guide
discord emojis put the name of the emoji and the id when sending it to chat like this:
<:emoji_name:0123456789>
This is the format you should use in your code as well otherwise discord has no idea which emoji you want to send.
Have u tried Using the Action Builder With the buttons
I'm from Cody Dimensions The Server u requested help from
Can u try your code like this:
const { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle } = ("discord.js")
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setActivity(`>>rank`, { type: "WATCHING" });
});
client.on("messageCreate", (message) => {
const row = new ActionRowBuilder()
.addComponents(
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
const btn2 = new ButtonBuilder()
.setLabel('YT')
.setEmoji("<1008747826714521610>")
.setStyle('Link')
.setURL('https://www.youtube.com/c/himisa')
const btn3 = new ButtonBuilder()
.setCustomId('btn2')
.setLabel('Click Me!')
.setStyle('Success')
);
if (message.content === 'hi'){
return message.channel.send({ content: 'HI' components: [row]}))
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
await interaction.channel.send('Um Hello');
}
}
});
client.login('SUPER SECRET TOKEN');
I Found Something To Fix This!
If You Are Using Default Emoji Use Unicode Emoji Like This π
If You Wanna Use A Custom Emoji You Have To Include :hi:123456789 Like This It Worked For Me
Also Remember To Not To Put The <>
import { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle, ActivityType } from "discord.js";
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setPresence({ activity: { name: 'with discord.js' }, status: 'idle' })
});
client.on("messageCreate", (message) => {
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
const btn2 = new ButtonBuilder()
.setLabel('YT')
.setEmoji(':hi:1010402480074539109')
.setStyle('Link')
.setURL('https://www.youtube.com/c/himisa')
const btn3 = new ButtonBuilder()
.setCustomId('btn2')
.setLabel('Click Me!')
.setStyle('Success')
if (message.content === 'hi'){
return message.channel.send({
content: 'HI' , components:[new ActionRowBuilder().addComponents(btn1,btn2,btn3)]
})
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
interaction.followUp({ content: 'Um Hello', ephemeral: true });
}
}
});
client.login('SUPER SECRET TOKEN');
In my previous question, I was recommended to try reconnecting to the port, and I have researched and have not been able to find out how. How can I do this?
const express = require("express");
const app = express();
app.listen(3000, () => {
console.log("Project is running!");
})
app.get("/", (req, res) => {
res.send("Hello World!");
})
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
client.on("messageCreate", message => {
if(message.content === "jobs") {
message.channel.send("fortnite battle royale");
}
})
client.on("messageCreate", message => {
if(message.content === "ping") {
message.channel.send("pong, you idiot, you should know the rest");
}
})
client.on("messageCreate", message => {
if(message.content === "pls dont help") {
message.channel.send(message.author.toString() + " " +"ok, i wont, all you had to do was ask... also dank memer stole this command");
}
})
client.on("messageCreate", message => {
if (message.author.bot) return;
if(message.content.includes("dream")) {
var msgnumber= (Math.floor((Math.random() * 2) + 1));
console.log(msgnumber);
if (msgnumber===1) {
message.channel.send("did someone say dream!?");
} else if (msgnumber===2) {
message.channel.send("why we talkin' about dream... huh!?");
}
}
})
client.on('messageCreate', message => {
if (message.content === '!ping') {
message.channel.send(`πLatency is ${Date.now() - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
}
});
client.on("messageCreate", message => {
if(message.content === "username") {
message.channel.send(message.author.username);
}
})
client.on('ready', () => {
console.log('Bot is online!');
client.user.setActivity('not being entertained', {type : 'PLAYING'} )
})
client.login(process.env.token);
Comment that suggested this: My bot has been offline with no error, it was working yesterday
I'm using this stripe extension and I am trying to pass the uid it gives me error firebase__WEBPACK_IMPORTED_MODULE_3___default.a.auth.onAuthStateChanged is not a function But I have Never seen this error before. please see the code below
import {loadStripe} from '#stripe/stripe-js';
import firebase from 'firebase';
const firestore = firebase.firestore();
firebase.auth().onAuthStateChanged((user) => {
if(user) {
console.log(user.uid) ;
}
});
export async function createCheckoutSession(uid){
firebase.auth.onAuthStateChanged((user) => {
if (user){
const checkoutSessionRef = firestore
.collection('customers')
.doc(user.uid)
.collection('checkout_sessions')
.add({
price: 'price id',
success_url: window.location.origin,
cancel_url: window.location.origin,
});
// Wait for the CheckoutSession to get attached by the extension
checkoutSessionRef.onSnapshot((snap) => {
const { error, sessionId } = snap.data();
if (error) {
// Show an error to your customer and
// inspect your Cloud Function logs in the Firebase console.
alert(`An error occured: ${error.message}`);
}
if (sessionId) {
// We have a session, let's redirect to Checkout
// Init Stripe
const stripe = loadStripe('pk_test_1234');
stripe.redirectToCheckout({ sessionId });
}
});
}
}
)}
Does anyone have any suggestions?
Try this:
(async () =>{
await firebase.auth().onAuthStateChanged((user) => {
if(user) {
console.log(user.uid) ;
}
});
} )();