Experiment with the Users.Get function available in vk-io

I am having an issue with a create command: Ban [@durov] and I encountered an error.

Here is how I attempted to solve the problem:

let uid = `${message.$match[1]}`
let rrr = uid.includes('@')
if(rrr == true){
let realid = uid.replace(/[@]/g, '')
await vk.api.users.get({ user_ids: realid }).then(res => {
    
let id = res[0].id
message.send(`ā›” [id${id}|User] has been banned.\nšŸ“ Reason: Testing`)
vk.api.messages.removeChatUser({ chat_id: message.chatId, member_id: id, user_id: id })
mongo.models.chatsusers.updateOne({ vkid: Number(id), join_chat: Number(message.chatId), banned: String(false) }, { $set: { banned: true } })
})
}

The error message I received is as follows:

TypeError: Cannot read properties of undefined (reading 'id')
    at C:\Users\User\Desktop\Nemo-MongoTest\bot.js:318:18
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async C:\Users\User\Desktop\Nemo-MongoTest\bot.js:316:2
    at async C:\Users\User\Desktop\Nemo-MongoTest\node_modules\middleware-io\lib\index.js:280:9

Interestingly, if I try this code in eval, it works without any issues.

Answer ā„–1

Resolved:

let userId = `${message.$match[1]}`
const hasEmail = userId.includes('@')
if(hasEmail){
    let cleanUserId = message.$match[1].replace("@", "")
    await vk.api.utils.resolveScreenName({ screen_name: cleanUserId }).then(async (response) => {
        console.log(response.object_id)
        const objectId = await response.object_id
        message.send(`ā›” [id${objectId}|User] has been banned.\nšŸ“ Reason: Testing 4 Re: ${cleanUserId}, ${response.object_id}, id: ${objectId}`)
        vk.api.messages.removeChatUser({ chat_id: message.chatId, member_id: objectId, user_id: objectId })
        mongo.models.chatsusers.updateOne({ vkid: Number(objectId), join_chat: Number(message.chatId), banned: String(false) }, { $set: { banned: true } })
    })
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The dimensions of the pop-up window in Chrome's JavaScript are not displaying correctly

My goal is to launch a new chat room window on our website. The dimensions of the chat room are set to 750px x 590px. Below is the link I am using to trigger the javascript popup. <a href="javascript:void(0)" onclick="window.open('http://gamersuni ...

Uncovering hidden links in a menu with Python Selenium and JavaScript

Can someone provide guidance on how to activate the JavaScript submenu associated with this button, "x-auto-54"? <table id="x-auto-54" class=" x-btn avtar-x-btn x-component x-btn-noicon x-unselectable " cellspacing="0" role="prese ...

Retrieving the value of a specific property nested within a JSON object using basic JavaScript

Hey there! Thanks for taking the time to check out my question. I'm diving into JavaScript and I've hit a roadblock trying to solve this particular problem: I'm looking to extract the value of a property nested within a JSON object under a ...

Is it possible to establish a connection between React and a MySQL Database?

I've been encountering issues with connecting to a remote database in React. Despite my efforts, I haven't been successful in establishing the connection. I have tried various solutions without any luck. The goal is simple - I just want to connec ...

Updating Bootstrap modal content based on button clickExplanation on how to dynamically change the content

I am looking to dynamically change the content displayed inside a modal based on the button that is clicked. For example, clicking button one will only show the div with the class 'one' while hiding the others. $('#exampleModalCenter&a ...

hold on for the arrays to be populated with data from the ajax calls

Currently, I am facing an issue on my page where I need to wait for all data to be loaded and stored in the appropriate arrays before proceeding with any actions. The data retrieval involves three separate AJAX calls, but sometimes the loading process take ...

Is there a way for me to see the changes I make in the react native source code reflected in the app

I have been making edits to the react native source code at this location: E:\project_name\node_modules\react-native\ReactAndroid\src\main\java\com\facebook\react\modules\statusbar\StatusBar ...

What are the steps to determine if a radio has been examined through programming?

In my form page, users can input an ID to fetch profile data from a MySQL database using AJAX. The retrieved data is then displayed in the form for editing. One part of the form consists of radio buttons to select a year level (e.g., "1", "2", "3", etc). ...

Is it beneficial to display three.js on a <canvas> rather than a <div>?

I have come across examples in three.js that use: renderer = new THREE.WebGLRenderer( { canvas: document.querySelector( 'canvas' ) } ); This relates to a <canvas></canvas> element. On the contrary, there is another method: rendere ...

Bring in Lambda layers on your local device

I've been trying to create a lambda function with a layer, but I'm stuck on how to get it running locally. Here's the current directory structure: - projectDir/ | - lambdas/ | | - match-puller/ | | | - scr/... | | | - index.ts | | ...

An error was encountered while attempting to proxy the request [HPM]

After cloning a GitHub repository, I ran npm i in both the root directory and client directories. I then created a development configuration file. However, when attempting to run npm run dev, nodemon consistently crashes with a warning about compiled cod ...

Postponed attaching event listeners to a Vue 3 instance within an iframe

Due to a specific requirement, I find myself in need of running a Vue instance inside an iframe. After some research and adjustments based on this thread from the Vue forum, I was able to achieve this goal while adapting the code for Vue 3 and removing unn ...

Can Vue.js be paired with pure Node.js as a backend without relying on Express?

After successfully building a project with both vue js and node js, specifically with express, I'm curious if it's feasible to solely utilize node js without frameworks like express. ...

What steps do I need to take to ensure that User.findByIdAndUpdate is executed only after the new password has been successfully set?

My code is intended to allow users to change their passwords when they want, but it seems that the hashing of the new password isn't working as expected. The issue appears to be related to the asynchronous nature of promises in JavaScript, where the l ...

Display and conceal different sections using hyperlinks

Hey there, I'm back with another issue related to this code snippet on jsfiddle: https://jsfiddle.net/4qq6xnfr/9/. The problem I'm facing is that when I click on one of the 5 links in the first column, a second div appears with 3 links. Upon clic ...

Empowering Components with React Hooks

I am currently in the process of transitioning from using class components to React hooks with the Context API. However, I am encountering an error and struggling to pinpoint the exact reason for it. Here are my Codes: // contexts/sample.jsx import React ...

Leveraging JavaScript to create a horizontal divider

Just a quick question - how can I create a horizontal line in Javascript that has the same customization options as the HTML <hr> tag? I need to be able to specify the color and thickness of the line. I am working on a website where I have to includ ...

Can JavaScript trigger an alert based on a CSS value?

Hello, I am facing an issue. I have created a blue box using HTML/CSS and now I want to use JavaScript to display an alert with the name of the color when the box is clicked. Below is my code: var clr = document.getElementById("box").style.background ...

Don't forget to keep track of when the user has closed

How can I ensure that the cache retains the user's action of closing the div? Currently, when I close the div and refresh the page, it reverts back to its original state. Is there a way to make this change persistent? Experience it live: Here is the ...

Improving React Efficiency: Should You Utilize Memoization of Axios GET Request Using useMemo or useCallback?

My Objective: I am currently working on a sizable function named getUnitedStatesCases, which involves making an Axios GET Request and performing various operations with the received data. I have already implemented it within a useEffect hook upon componen ...