TypeError: Cannot read property 'get' of undefined when writing command - typeerror

I am in the process of making my first discord bot, and right now I am in the process of making a "kick" command for my bot. However, whenever I run the "kick" command, it tells me the TypeError: Cannot read property 'get' of undefined error. I've tried everything, can someone help me?
My kick command:
module.exports = {
name: 'kick',
description: "This command kicks a member!",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.member.cache.get(target.id);
memberTarget.kick();
message.channel.send("User has been kicked");
}else{
message.channel.send(`You coudnt kick that member!`);
}
}
}

Related

First time when it runs it fails but when i hit re-run it works perfectly

For some reasons when i try to run my cypress code it fails (during the first initialization) and it throws an error like the variables im setting out of the file doesn't exist. (when they actually are...)
After it fails i click on the re-run button and everything works perfectly, what im trying to avoid is the problem with the ghost variables at the beginning... I tried different approaches like setting the variable to an environment variable, and nothing seems to work.
I have this constants in an external file:
export const constants = {
access_token: "",
_id: "",
payment: {},
access_token_QR: "",
QRCode: "",
url: "https://google.com/"
}
And on each cypress test for example i have something like this:
it("login SSO", () => {
constants.access_token = "asfdaaFDSA"#$20ASDG0A"#$ASDJFAJM2"
}
Then after that it goes to the next test:
it("Another test", () => {
cy.log(constants.access_token) // it does print the code.
}
And when it reaches a test that does a cy.visit it doesn't detect the url constants.url but when i reload the cypress it works perfectly for some reason i can't explain.
Is there any setting im currently missing?
I tried setting the variable in the same file but is not passing until it reloads the website i believe is something related to cache that makes it works?

Playing an audio file with source => {uri: 'remote-file-path'} not working - React Native (expo)

I keep getting this error when i try to play an audio from my local backend or an already uploaded audio from a site.
No matter what file format, this is what I get and this only happens with ios
error: Possible Unhandled Promise Rejection (id: 0): Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain". Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
error image
const player = new Audio.Sound();
player.loadAsync({ uri: url }, initialStatus).then(() => {
player.playAsync().then((playbackStatus) => {
if (playbackStatus.error) {
handlePlaybackError(playbackStatus.error);
}
});
});
After adding more error handling, I found out the error comes from loadAsync and it only happens when I try to play an audio from my local backend server. (ex: http://127.0.0.1:8000/media/audios/2021/08/08/27/21/filename.mp4)
It would be really great if I could get help on this, thanks in advance!
Update: Provided more code
So I found out that the that warning was being generated and preventing my audio files from playing because they are stored in my local server and for some reason the expo Audio.Sound object had an issue loading them, so I had to install expo-file-system, use the FileSystem to read download the file and use the uri produced from the download.
Example:
import * as FileSystem from 'expo-file-system';
const splitUrl = url.split('/');
const lastItem = splitUrl[splitUrl.length - 1];
const { uri } = await FileSystem.downloadAsync(
url,
FileSystem.documentDirectory + lastItem
);
const source = { uri: uri }; //the source you provide to the loadAsync() method
loadAsync() returns a Promise, so you have to await it.
If this is not the problem you have to provide more code, please.
Here's the documentation, so use it like this:
const sound = new Audio.Sound();
try {
await sound.loadAsync(require('./assets/sounds/hello.mp3'));
await sound.playAsync();
// Your sound is playing!
// Don't forget to unload the sound from memory
// when you are done using the Sound object
await sound.unloadAsync();
} catch (error) {
// An error occurred!
}
And here's a simple snack I made, it works for me, you might want to consider error handling using try-catch:
Snack example

Set up Cypress IO to work with dotenv on Quasar Framework

I'm using Quasar framework and just after I've added quasar-dotenv package I realized that e2e tests not working.
Uncaught TypeError: fs.readFileSync is not a function
This error originated from your test code, not from Cypress.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
Check your console for the stack trace or click this message to see where it originated from.
at Object.config (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:141291:34)
at Object.746.eslint (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:150393:36)
at o (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:265)
at http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:316
at Object.747.../../../../quasar.conf.js (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:150535:35)
at o (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:265)
at r (http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:431)
at http://localhost:8080/__cypress/tests?p=test/cypress/integration/home/init.spec.js-312:1:460
I've tried to set up the Cypress environment by adding the test/cypress/plugins/cypress.env.json file with some data, as well as changing the test/cypress/plugins/index.js file in the same folder, by following this documentation as it was suggested here:
const env = require('quasar-dotenv').config()
module.exports = (on, config) => {
// config.env.API_URL = 'http://example.com' // not working
config.env = env
// Chrome:: Hack for shaking AUT. Cypress Issue: https://github.com/cypress-io/cypress/issues/1620
on('before:browser:launch', (browser = {}, args) => {
if (browser.name === 'chrome') {
args.push('--disable-blink-features=RootLayerScrolling');
return args;
}
return true;
});
return config
};
MacOS Catalina
Cypress v3.5.0
Chrome v77
I don't know the answer because I am unfamiliar with quasar-dotenv. Have you tried the official quasar dotenv app extension? https://github.com/quasarframework/app-extension-dotenv or, alternatively, another official app extension, but less opinionated than dotenv wrappers: https://github.com/quasarframework/app-extension-qenv

problem accessing elements using id/name for login form in cypress

I am trying to login to a form written in angular js but cypress throws the following exception:
Uncaught TypeError: $(...).materialScrollTop is not a function
This error originated from your application code, not from Cypress.
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the 'uncaught:exception' event.
https://on.cypress.io/uncaught-exception-from-application
This is the cypress login code:
context('TestLogin', () => {
it('Test Login', () => {
cy.visit('url');
cy.get('input[id=Email]').type('email', {force: true});
cy.get('input[id=Password]').type('passcode', { force: true });
cy.get('button[type=submit]').click();
})
})
Since the login has a csrf token, I have used cy.request() as follows and I do get a response with status code 200 but when re-loading the site it goes back to login page.
describe("Tests for AntiForgeryToken", function () {
// variable from config, that contain Identity Server URL
const identityUrl = Cypress.config("identityServerUrl")
// command declaration that we are going to use in tests
// allows us to create request to server
Cypress.Commands.add("loginByToken", function (token, login, password) {
cy.request({
method: "POST",
failOnStatusCode: false,
url: `${identityUrl}/Account/Login`,
form: true,
body: {
email: login,
password: password,
__RequestVerificationToken: token,
RememberLogin: false
}
})
})
it("Should parse token from response body and return 200", function () {
cy.request(`${identityUrl}/Account/Login`)
.its("body")
.then((body) => {
const $html = Cypress.$(body)
// when the page is rendered
// we are trying to find the Request Token in the body of page
const token = $html.find("input[name=__RequestVerificationToken]").val()
// POST request with token and login data
// then we simply verify whether Indentity Server authorized us
cy.loginByToken(token, "test#test.com", "Test_1234")
.then((resp) => {
expect(resp.status).to.eq(200)
})
})
cy.visit(`${identityUrl}/Account/`);
})
Cypress documentation didn't provide much info about the exception.
Any insights from cypress experts are helpful.
As evident from the error, Cypress is failing the test as it found an exception in your application,this is not a cypress level exception but an uncaught exception in your app which is causing cypress to fail the test, this is pretty useful as you can check if its an actual error in your app and log it for the dev team to fix, check if you are able to reproduce this manually, either way i think the application code should be fixed to either fix the bug or catch the exception and return a valuable error message. If you want to disable this feature you can turn off all uncaught exception handling, so in your index.js or whatever file is the entry point add the following:
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
// you can also add a Debugger here to analyze the error
debugger;
return false;
});
not sure if turning this off will help as looks like there is something in your application which could be an issue, but this is just for informational purposes that you can turn this feature off if you needed to.
Here is the documentation for further reading : Cypress Events documentation
hope this helps

Titanium App Crash With a Simple Get Request - Uncaught TypeError

I am trying to fetch data from a simple get request using Titanium.Network.HTTPClient
Here is the code
var url = "http://www.appcelerator.com"; //Here i have my get api URL, i have also tried replacing the url with google.com
var client = Ti.Network.createHTTPClient({
// function called when the response data is available
onload : function(e) {
Ti.API.info("Received text: " + this.responseText);
alert('success');
},
// function called when an error occurs, including a timeout
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000 // in milliseconds
});
// Prepare the connection.
client.open("GET", url);
// Send the request.
client.send();
But the app is crashing with error Uncaught TypeError: Cannot read property 'extendModel' of undefined, I am not using any model, It is a new project with the above mentioned code, nothing more.
Here is the screenshot of error
Please help!
EDIT
Configuration details:
Titanium Command-Line Interface, CLI version 5.0.13
Titanium SDK
version 6.0.4.GA
Node version v4.8.2
Please let me know if any further details required,