Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I have used Discord.js before and everything has been fine. For some reason lately Discord.JS has been buggy and has problems. In this code I try making a simple on message event command for "ping", also have tried to set the presence. Nothing happens for any of it. Once the bot is online it does print out that the bot im using is online "Bot#9796" and it does actually turn online + correct token. I'm unsure why the command doesn't work and why it doesnt print out all messages and also the status. If anyone knows how to fix all of this being broken please let me know! Thanks.
Here is the code
const { Client, GatewayIntentBits } = require('discord.js');
const dotenv = require('dotenv');
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setPresence({
activity: {
name: 'with Discord.js'
},
status: 'online'
});
});
client.on('message', message => {
console.log(message.content);
if (message.content === 'ping') {
message.channel.send('pong');
}
});
client.login(process.env.DISCORD_TOKEN);
The message event has been renamed to messageCreate in v14, try renaming the event.
Related
I am trying to edit a message that was sent in a DM. Here is the code that does this:
async execute(interaction){
//function...
//member and gameData are defined
//remove the message containing the buttons and send a new one
//build new embed
const gmEmbed = new EmbedBuilder()
.setTitle(`Approved Join Request`)
.setDescription(`${member.user.tag} has successfully joined ${gameData.gameName}.`)
.setColor(0x33ff88);
try {
await interaction.message.edit({ embeds: [gmEmbed] });
}
catch (e) {
console.log(`[WARN] Unable to edit a DM to ${interaction.user.tag} accepting a player:\n${e}`);
}
//rest of function...
}
And this is what happens when the interaction is created and this function is run:
[WARN] Unable to followup a DM to username redacted accepting a player:
Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
In index.js I have the client logging in with const client = new Client({ intents: [..., GatewayIntentBits.DirectMessages] }); but I'm not sure if that's relevant to this issue.
How can I edit a message in a DM?
Edit 1: interaction.message.fetch().then(message => message.edit(...)) doesn't work. interaction.channel returns null. I believe the gateway intent should allow this, but it doesn't seem to. Also, strangely it seems to work sometimes, seemingly the first time the function is called for that interaction.
You can use interaction.editReply() to edit the reply to an interaction.
// ...
try {
await interaction.editReply({ embeds: [gmEmbed] });
} catch (e) {
console.log(`[WARN] Unable to edit a DM to ${interaction.user.tag} accepting a player:\n${e}`);
}
This question already has an answer here:
client.user.setActivity found as null? (Node.js)
(1 answer)
Closed 9 months ago.
So I am trying to set a activity for my bot, but it will only give me the error:
Cannot read properties of null (reading 'setActivity')
So how do I set that right in the config.json? (it needs to be in the index as well)
Index.js:
client.user.setPresence({
activities: [{
name: presenceName,
type: presenceType,
}],
status: presenceStatus,
});
})
client.user.setActivity(`serving ${client.guilds.cache.size} servers`);
config.json
{
"prefix": ".",
"presenceName": "EVERYONE",
"presenceType": "WATCHING",
"presenceStatus": "ONLINE"
}
First of all, you can only call .setActivity() after the bot comes online so it will need to be in the client.on('ready') callback function and as per your current code, we cannot see if it is in the .ready function so we can assume that it is. After that, when calling .setActivity(), you also need to mention whether the bot is either STREAMING, PLAYING, LISTENING or WATCHING. So the correct usage for this command would be:
client.on('ready', () => {
console.log('The bot is online!')
client.user.setActivity('demo', { type: 'WATCHING' })
})
You can learn more about .setActivity() here => discord.js | ClientUser
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I have ploblems with English. I apologize in advance.
Problems with firestore and auth
Error: [firestore/permission-denied] The caller does not have permission to execute the specified operation.
NativeFirebaseError: [firestore/permission-denied] The caller does not have permission to execute the specified operation.
My rules in FireStore:
rules_version = '2';
service cloud.firestore {
match/databases/{database}/documents {
match /Users/{document=**} {
allow read, get: if true;
allow create, update: if request.auth.uid == resource.id;
}
}
I using npm package:
#react-native-firebase/app
#react-native-firebase/app-check
#react-native-firebase/auth
#react-native-firebase/firestore
My code:
import auth from '#react-native-firebase/auth';
import firestore from '#react-native-firebase/firestore';
async function onAuthChanged(onChange) {
auth().onAuthStateChanged(onChange);
}
async function authenticateUser(status) {
if (status) {
const uid = status.uid;
let user = await firestore().collection('Users').doc(uid).get(); // Error
return ({
user: {...user.data(), uid} ?? {login: undefined, birthday: undefined, uid}
});
} else {
return { user: null };
}
}
onAuthChanged(async (status) => {
const { user } = await authenticateUser(status);
});
P.S. In fireStore my rules work: enter image description here
P.S.S. This is my first time working with Firebase and everything worked for the first two weeks with standard rules, but today it gives an error. and I do not know why. Although they offer me to put true on all the rules. This does not help in any way for 6-7 hours I have been trying to understand, so I have already turned here.
In firestore, if you got any permission denied. This is because firestore security rules.
Change your rules to:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have two pages named Login and Welcome. I noticed that I cant run dispatch before login.
To be more understandable I leave an example below;
On Login Page dispatch(fetchUser())) doesn't trigger saga
Login Page =>
const fetchUserLocal = () => {
console.log("dispatch run, before user login: ",dispatch(fetchUser()))
dispatch(fetchUser())
}
return ( <div> <button onClick={fetchUserLocal}>Click to FETCH USER</button> </div>)
On Welcome Page dispatch(fetchUser())) trigger the saga
(The page can be accessible after logging in) Welcome Page =>
const fetchUserLocal = () => {
console.log("dispatch run, after user login: ",dispatch(fetchUser()))
dispatch(fetchUser())
}
return ( <div> <button onClick={fetchUserLocal}>Click to FETCH USER</button> </div>)
Both pages have useDispatch and action and I can reach on these pages.
According to your request I can add more information,
thanks for help
I figure out the problem, It's all my mistake.
Welcome page is working because when fetchUser in that page I have a session, and my backend API return success and the code runs in the try block.
But I don't have any session when I fetch the user on Login page, and backend API returns credential error, and code runs in catch.
The problem start here because I have missed parantesies. It works now well when I change yield put(fetchUserFailure) to yield put(fetchUserFailure())
export function* fetchUser() {
try {
console.log("fetchUser")
const user = yield axios.get(FETCH_USER, { withCredentials: true });
console.log("saga outh user",user)
yield put(fetchUserSuccessful(user.data));
} catch (error) {
console.log("error",error)
yield put(fetchUserFailure);
}
}
I was using a helper package for actions and reducers. The package name is react-act. I don't know why but when I removed this package I didn't get the same error. Everything is okay now.
If I learn the what I did wrong with react-act I will leave a comment here, if you already know or have a guess, please leave a comment.
I am trying to make a bot that would add a role that is in the server when a person types !join choiceOutOfVariousRoles. I am currently using discord version 12. My error message is:
fn = fn.bind(thisArg);
Although trying various techniques I could not get the code to work.
const Discord = require('discord.js');
const client= new Discord.Client();
const token = process.env.DISCORD_BOT_SECRET
client.on('ready', () => {
console.log("I'm in");
console.log(client.user.username);
});
client.on('message', msg => {
if (msg.content.toLowerCase().startsWith("!join"))
{
var args = msg.content.toLowerCase().split(" ")
console.log(args)
if (args[1] === 'sullen')
{
msg.channel.send('You have successfully joined Sullen!')
const sullenRole = msg.guild.roles.cache.find('name','Sullen')
msg.member.addRole(role.id)
}
}
});
client.login(token)
**EDIT: Fixed what everyone was saying and all I need to do now Is update the permissions, (my friend has to do that because its not my bot) and I should be all good. Thanks everyone! :D
discord.js introduces breaking changes very frequently, and v12 is no exception. You need to make sure you find up-to-date code otherwise it won't work. GuildMember#addRole was moved to GuildMemberRoleManager#add, which means you must use msg.member.roles.add(sullenRole).