NodeJS discord-rpc application not found - javascript

I am trying to setup Discord RPC. For it, I registered a new application and copied the client ID.
Then I am using this code:
const RPC = require("discord-rpc");
const discordClient = new RPC.Client({ transport: "ipc" });
let defaultActivity;
(async () => {
discordClient.on("ready", async () => {
console.log('Authed for user', discordClient.user);
console.log(discordClient.application.name);
console.log(discordClient.user.username);
defaultActivity = {
details: `${discordClient.user.username}`,
state: "Test",
largeImageKey: "test",
largeImageText: "Kirka Client",
smallImageText: `${discordClient.user.username}#${discordClient.user.discriminator}`,
}
discordClient.setActivity(defaultActivity);
});
await discordClient.login({clientId: "871730144836976650"}).catch(console.error)
})();
But this gives me the following error:
Authed for user { id: '771601176155783198',
username: 'AwesomeSam',
discriminator: '7985',
avatar: '93d3fd4fb9fd0921830d69e07a248036',
bot: false,
flags: 176,
premium_type: 1 }
(node:6664) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of null
at RPCClient.discordClient.on (D:\kirkaclient\src\features\discordRPC.js:9:47)
at RPCClient.emit (events.js:198:13)
at RPCClient.login (D:\kirkaclient\node_modules\discord-rpc\src\client.js:139:12)
at process._tickCallback (internal/process/next_tick.js:68:7)

Well, it is as it says.
Cannot read property 'name' of null
It seems that the property "discordClient.application" in line 9 is null, so it could not read a "name" value of null.
I'm not into discord-rpc, I do prefer discord.js, so I can't come up with a solution for this.
You should try debugging it with console.log(discordClient)

Related

DiscordAPIError[40060]: Interaction has already been acknowledged. I am trying to change button colour

I am trying to make a tic-tac-toe game. I found some code, but it doesn't work well. When you click on the button then it should change the button color and text. The problem is when I click
writes to discord "The application does not respond"
work fine
throw an Error
I am using discord.js 14
If you have a better code then send it here, this is the only one which I found.
Code:
if (interaction.isButton()) {
const collector = interaction.channel.createMessageComponentCollector();
collector.on("collect", async (i) => {
//loop through each action row on the embed and update it accordingly
let newActionRowEmbeds = i.message.components.map((oldActionRow) => {
//create a new action row to add the new data
const updatedActionRow = new ActionRowBuilder();
// Loop through old action row components (which are buttons in this case)
updatedActionRow.addComponents(
oldActionRow.components.map((buttonComponent) => {
//create a new button from the old button, to change it if necessary
const newButton = ButtonBuilder.from(buttonComponent);
//if this was the button that was clicked, this is the one to change!
if (i.component.customId == buttonComponent.customId) {
//If the button was a primary button then change to secondary, or vise versa
if (buttonComponent.style == ButtonStyle.Primary) {
newButton.setStyle(ButtonStyle.Secondary);
newButton.setLabel("X");
}
}
return newButton;
})
);
return updatedActionRow;
});
// and then finally update the message
await i.update({components: newActionRowEmbeds});
});
}
Error:
C:\Users\vojta\tictactoe\node_modules\#discordjs\rest\dist\index.js:667
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[40060]: Interaction has already been acknowledged.
at SequentialHandler.runRequest (C:\Users\vojta\tictactoe\node_modules\#discordjs\rest\dist\index.js:667:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (C:\Users\vojta\tictactoe\node_modules\#discordjs\rest\dist\index.js:464:14)
at async REST.request (C:\Users\vojta\tictactoe\node_modules\#discordjs\rest\dist\index.js:910:22)
at async ButtonInteraction.update (C:\Users\vojta\tictactoe\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:233:5)
at async InteractionCollector.<anonymous> (file:///C:/Users/vojta/tictactoe/src/index.js:115:3) {
requestBody: {
files: [],
json: {
type: 7,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: [ { type: 1, components: [Array] } ],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1049732802192617552/aW50ZXJhY3Rpb246MTA0OTczMjgwMjE5MjYxNzU1Mjp5d1FqWGh4bU82eVh1eVBrRWJsZnhWS2FibjZqSWNRMWhaSWN2YlZ1YU5nVHZsdEw2VUxZWGEzb0JQcHJQaUFPQVkyeHJ1NGp0WXZNUlE1all2YmkyQlA2ZHlpRUQ2ZUhDSUFUeVNWYkREaVc4OFdLWmVoMlpZUXJnQ1M5eWdyQw/callback'
}
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...

TypeError: Cannot read property 'data' of undefined Discord-Hybrid-Sharding

So I decided to shard my discord bot using discord-hybrid sharding. Everything seemed to be fine. When I ran the code I rand into the error TypeError: Cannot read property 'data' of undefined. Here is the bot.js code
const Discord = require("discord.js");
const { Cluster } = require("discord-hybrid-sharding");
const client = new Discord.Client({
shards: Cluster.data.SHARD_LIST,
shardCount: Cluster.data.TOTAL_SHARDS,
allowedMentions: {
parse: [],
repliedUser: false,
},
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_VOICE_STATES,
],
presence: {
activity: {
name: `w!help | Wolf Music`,
type: "PLAYING",
},
status: "online"
}
});
...
client.on("ready", () => {
require("./dashboard/index.js")(client);
})
here is the index.js code
const Cluster = require("discord-hybrid-sharding");
const { token } = process.env.TOKEN
const manager = new Cluster.Manager(`${__dirname}/bot.js`, {
totalShards: 9,
shardsPerCluster: 2,
mode: "process",
token: token,
respawn: true,
userv13: true,
});
manager.extend(
new Cluster.HeartbeatManager({
interval: 2000, // Interval to send a heartbeat
maxMissedHeartbeats: 5, // Maximum amount of missed Heartbeats until Cluster will get respawned
})
)
According to the code (in my observation) it should work with no issues
expected outocome:
Launched shard: 0
Launched shard: 1
Launched shard: 2
Launched shard: 3
Launched shard: 4
logged in to bot
real outcome:
shards: Cluster.data.SHARD_LIST,
^
TypeError: Cannot read property 'data' of undefined
Please dont fork this just look at the console
Is it an issue from my side or replit side:
djs: 13.1.0
nodejs: 12.22.0

Error : RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string

I'm trying to make a regular send command that takes the content from the slash command, but I get this error, I tried to fix it according to the previous answers that I received here, but, unfortunately, it doesn't work either.
RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string.
at Function.verifyString (C:\Users\wiskj\Desktop\adminadminov\node_modules\discord.js\src\util\Util.js:416:41)
at MessagePayload.makeContent (C:\Users\wiskj\Desktop\adminadminov\node_modules\discord.js\src\structures\MessagePayload.js:114:22)
at MessagePayload.resolveData (C:\Users\wiskj\Desktop\adminadminov\node_modules\discord.js\src\structures\MessagePayload.js:129:26)
at TextChannel.send (C:\Users\wiskj\Desktop\adminadminov\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:171:61)
at module.exports (C:\Users\wiskj\Desktop\adminadminov\commands\send.js:5:19)
at module.exports (C:\Users\wiskj\Desktop\adminadminov\events\interactionCreate.js:13:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
Code:
module.exports = async (bot, message, args, argsF) => {
const {channel} = message;
const content = Array.from(argsF).join(" ")
await channel.send(content);
};
module.exports.names = ["send"];
module.exports.interaction = {
name: 'send',
description: 'Отправить сообщение от имени бота',
options: [
{
name: "сообщение",
description: "Укажите что хотите отправить",
type: "STRING",
required: true
},
],
defaultPermission: true
}, "962964961687138385";
module.exports.names = ['send'];
As the error says, message content must be non-empty-strings.
channel.send(`${content}`)
or
channel.send(String(content))
Either of these will work, since both are converting content into a String.

Error: An API error occurred: invalid_auth

Hi I'm writing my slack bot, and I want after select, change prev message to a new variat, this is my action which is triggerd after select:
slackInteractions.action({ type: "static_select" }, (payload, res) => {
console.log(payload);
web.chat
.update({
token: slackSigningSecret,
channel: payload.container.channel_id,
ts: payload.container.message_ts,
as_user: true,
text: "Hello World"
})
.catch(err => {
console.log(err);
});
});
And I got error:
Error: An API error occurred: invalid_auth
at Object.platformErrorFromResult (/home/codex/Documents/dan-bot/node_modules/#slack/web-api/dist/errors.js:50:33)
at WebClient.apiCall (/home/codex/Documents/dan-bot/node_modules/#slack/web-api/dist/WebClient.js:485:28)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 'slack_webapi_platform_error',
data: { ok: false, error: 'invalid_auth', response_metadata: {} }
}
This is payload:
{
type: 'block_actions',
team: { id: '//', domain: '*** },
user: {
id: 'U010Q9X59QT',
username: '**',
name: '***',
team_id: '//'
},
api_app_id: '///',
token: '***',
container: {
type: 'message',
message_ts: '1585662258.008100',
channel_id: '****',
is_ephemeral: true
},
trigger_id: '1038328652789.1035324920279.b84d3403b8e44ab0cd53c997ba8b4c72',
channel: { id: '***', name: 'directmessage' },
response_url: 'https://hooks.slack.com/actions/T01119JT287/1040413692903/6TWTQqXhcp453TPREb7uRcPn',
actions: [
{
type: 'static_select',
action_id: 'wkR',
block_id: 'LM9',
selected_option: [Object],
placeholder: [Object],
action_ts: '1585662260.040519'
}
]
}
As token I use my main slack token, using this I'm trying to change block where I seelcted variant to another block, at the moment trying to change as string "Hello world"
Thanks in forward!!!!
Looking back at their documentation for chat.update, the token should be the access token you see on the Oauth & Permissions tab and it starts with xoxb or xoxp. Please check more about their Oauth documentation here: https://api.slack.com/authentication/oauth-v2
I faced the same issue, and eventually found out it was caused by passing the wrong token (copy-paste issues).
What helped me debug it:
Check the structure of the token. Most modern tokens start with xoxb- and have a length of 56 characters
Test that the token works before wrapping it in code, using e.g. Slack's auth test API

Cannot read property 'castForQuery' of undefined at castArrayFilters in Node.js

I am using arrayFilters as option in findOneAndUpdate (in mongoose) to update value of name and isRecursive fields in TimetableModel.
The fields are updating successfully in MongoDb but also I am getting the exception, which is being added at the end of this query.
What am I supposed to do to eliminate this exception?
Following are the details of my work:
Versions: "mongodb": "^3.1.13",
"mongoose": "^5.4.9",
this is the Schema:
const timetableSchema = new Schema({
individualId: {
type: Schema.Types.ObjectId,
required: true
},
date: {
type: Number,
required: false
},
time: []});
this is the logic:
TimetableModel.findOneAndUpdate({
individualId: req.query.individualId,
date: req.query.date,
}, {
'time.$[i].name': req.query.name,
'time.$[i].isRecursive': req.query.isRecursive,
}, {
arrayFilters: [{
'i.timeSlot': req.query.timeSlot
}],
}, function (err, result) {
if (result) {
resolve(result);
} else if (err) {
reject(err);
}
}).catch((err) => {
reject(err);
})
and this is the exception
"TypeError: Cannot read property 'castForQuery' of undefined
at castArrayFilters (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/helpers/update/castArrayFilters.js:59:37)
at _castArrayFilters (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:1739:5)
at model.Query.Query._findAndModify (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:3205:3)
at model.Query. (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/query.js:2830:8)
at model.Query._wrappedThunk [as _findOneAndUpdate] (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/mongoose/lib/helpers/query/wrapThunk.js:16:8)
at process.nextTick (/Users/user/Desktop/Projects/ParentsPlus/ParentsPlusRepo/parents-plus-back-end/node_modules/kareem/index.js:369:33)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)"
I think there is a bug since version 5.4.4 or maybe another previous version. It was reported here. For the moment I solved it by downloading the mongoose version to 5.3.15.

Categories

Resources