Category: javascript
Category Added in a WPeMatico Campaign
Cannot read properties of undefined (reading ‘bannable’)
message.mentions.members.forEach(men => {
let member = message.mentions.members.get(men)
if (!member.bannable) return message.reply(not_bannable)
const reason = args.slice(1).join(" ");
member.ban({reason: reason || "no reason"}).then((member) => {
message.channel.send(member + " banned by " + message.author.id)
}).catch(err => console.log(err))
})
I’m trying to build a ban command that allows you to ban multiple users at once. Unfortunately, an error occurs when I execute it.
I work with discord v13
Why does this error occur?
Cannot read properties of undefined (reading 'bannable')
How can you make the bounding box of text in an HTML5 canvas account for transformations such as panning and scaling?
I’ve been playing with a Javascript program which is composed of an HTML5 Canvas that can be panned and zoomed. Text can also be added and a bounding box is initially generated for it. I’ve got the program to account for the panning transformations, but I’m unable to get the bounding box to account for the scaling/zooming in and out. The initial bounding box is also not perfect, although it works when you try to click and drag the text, it is off by quite a bit.
Please help me figure out how to fix these issues.
Here is the program: https://jsfiddle.net/HappyAcorn77/hekagmb2/2/
/* I use this code to account for panning transformations for the bounding box on line
362
The Zooming/Scaling function can be found on line 372 which is what I am unable to
adjust the bounding box for.
*/
- Click and hold to drag the text
- Left click to default to inital display transformation values
query load page go instantly to div
i have problem with scroll. Its working fine, but i want to make it instantly without any animation, just then page refreshing be the same place as before without scrolling to the place.
my js code.
<script type = "text/javascript">
$(function() {
$(window).scrollTop( $("#col-6").offset().top)
});
</script>
My project structure for example.
First including css and html
<?php
include(html/css.php);
some code....
<div class=col-6>
some code....
</div>
include(footer.php);
?>
so in footer php after
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://kit.fontawesome.com/5fbb5e690d.js" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.js"></script>
i use my js code.
And after page load its scrolling to col-6 div. But, i want instantly without any animation or scrolling be in what place.
What i try
<script>
$(window).on('beforeunload', function() {
$('body').hide();
$(window).( $("#col-6").offset().top)
});
</script>
any1 have solution for it ?
How to copy all images from a src folder to a dist folder recursively using copy files npm module?
Using the copy files command, how can I copy images (.png, .jpg) from a “src” folder to the “dist” folder, while preserving the same filepaths internally. Should also work recursively.
https://www.npmjs.com/package/copyfiles
I have this
copyfiles(["src/**/*.png", "dist"], {u:2}, (err) => {
if (err) {
console.log("Error occurred while copying", err);
}
console.log("folder(s) copied to destination");
});
But it doesn’t seem to work. It creates the src
folder inside dist
folder.
Thanks
requerir faker y nuestra error module not fou [closed]
este error me da cuando ejecuto el comando node index.js
mm@MadMacBook-Pro src % node index.js
internal/modules/cjs/loader.js:329
throw err;
^
Error: Cannot find module '/Users/mm/Desktop/ddd/node_modules/faker/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:321:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:534:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/Users/mm/Desktop/ddd/src/index.js:1:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) {
code: 'MODULE_NOT_FOUND',
path: '/Users/mm/Desktop/ddd/node_modules/faker/package.json',
requestPath: 'faker'
}
How to make a dropdown menu transition with CSS?
I have created a responsive navigation-bar/menu but I want it to appear with a sliding animation from the top to the bottom when the needed button is presed. The menu does appear on itself but it completely ignores the transitioni have set it to execute. I tried multiple methods – using webkit library, using the change in height method, etc. It appears that none of them work with my code. If anyone can help, please reach to me.
const toggleButton = document.querySelector('.dot_a');
const navbarLinks = document.querySelector('.nav-list');
toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active')
})
body {
background-image: url(1.jpg);
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
margin: 0;
}
.pro_column1 {
width: 15%;
}
.pro_column2 {
width: 85%;
}
.nav {
overflow: hidden;
background-color: white;
/*opacity: 60%;*/
margin: 10px;
border-radius: 10px;
width: 850px;
/*background:#3c6382;
/*box-shadow:0px 5px 20px rgba(0,0,0,0.1);*/
/*border: solid black 2px;*/
}
.nav a {
color: #747d8c;
text-align: center;
padding: 27px 10px;
text-decoration: none;
font-size: 17px;
margin: 0;
border-radius: 10px;
transition: 1s;
}
.nav a:hover {
background-color: #ddd;
color: black;
-webkit-animation: 1s ease-in forwards;
}
.dot_a {
padding: 25px 10px;
font-size: 17px;
text-align: center;
margin: 0;
display: inline-block;
border-radius: 10px;
transition: 1s;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
i {
/*float: right;*/
font-size: 20px;
border: none;
outline: none;
color: #747d8c;
padding: 25px 5px;
font-family: inherit;
margin: 0px;
border-radius: 20px;
transition: 1s;
}
.dot {
height: 15px;
width: 15px;
border-radius: 50%;
display: inline-block;
margin: 0px;
}
.column {
float: left;
width: 33.33%;
padding: 10px;
height: 300px;
}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 870px) {
.nav a {
padding-top: 5px;
padding-bottom: 5px;
display: block;
}
.dot_a {
padding-top: 3px;
padding-bottom: 0px;
}
.nav {
width: 90%;
}
.dot {
margin-top: 15px;
margin-bottom: 15px;
}
.nav-list{
display: none;
overflow: hidden;
}
.nav-list.active {
display: block;
overflow: visible;
margin: 0;
padding: 0;
-webkit-transition:max-height 500ms ease-in;
-moz-transition:max-height 500ms ease;
-o-transition:max-height 500ms ease;
transition:max-height 500ms ease;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Начало</title>
<link rel="shortcut icon" type="image/png" href="favicon.jpg">
<link rel="stylesheet" href="IndexStyle.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://kit.fontawesome.com/d2896764d5.js" crossorigin="anonymous"></script>
</head>
<body>
<center>
<nav class="nav">
<div class="dot_a">
<span class="dot" style="background-color: transparent; width: 5px; height: 5px;"></span>
<span class="dot" style="background-color: #ff4757;"></span>
<span class="dot" style="background-color: #ffa502"></span>
<span class="dot" style="background-color: #2ed573;"></span>
</div>
<span class="nav-list">
<a class="anchors" href="Index.html"><i class="fas fa-house-damage"></i> НАЧАЛО</a>
<a class="anchors" href="HtmlPage.html"><i class="fas fa-code"></i> HTML&CSS</a>
<a class="anchors" href="#"><i class="fas fa-tools"></i> ИНСТРУМЕНТИ</a>
<a class="anchors" href="#"><i class="fas fa-thumbtack"></i> ЗАДАЧИ</a>
<a class="anchors" href="#"><i class="far fa-address-card "></i> ЗА НАС</a>
</span>
</nav>
</center>
<script src="ResponsiveMenu.js" ></script>
</body>
</html>
replit node.js to 000webhost
I’ve been trying to make one for a while but I’m just too bad.
I want it so when you type $whitelist (the ip)
it automatically changes only the
$ip = array(‘ip address’,);
on 000webhost main.php
please help
How do you refactor a React functional component with many useState and useEffect interactions?
I need some advice. It’s getting complicated to make changes with all the state and effect interactions.
How to write a quickSort function using prototypes
How do you write a quickSort function using the prototype
//Start of Array function?
//I dont know what more to say or how to explain what I am doing here.
function ArrayList() {
this.items = [];
}
ArrayList.prototype.insert = function(item) {
this.items.push(item);
}
ArrayList.prototype.toString = function() {
return this.items.join();
}
//This is a function to create a non sorted array using the array function above
function createNonSortedRandomArray(size) {
var elements = size;
var array = new ArrayList();
for (var i=elements; i>0; i--) {
array.insert(i);
}
return array;
}
swap = function(array, index1, index2) {
var aux = array[index1];
array[index1] = array[index2];
array[index2] = aux;'
// quickSort function begins here
ArrayList.prototype.quickSort = function() {
quick(this.array, 0, this.array.length - 1);
}
quick = function(array, left, right) {
var index;
if (array.length > 1) {
index = partition(array, left, right);
if (left < index - 1) {
quick(array, left, index - 1);
}
if (index < right) {
quick(array, index, right);
}
}
};
partition = function(array, left, right) {
var pivot = array[Math.floor((right + left) / 2)],
i = left,
j = right;
while (i <= j) {
while (array[i] < pivot) {
i++;
}
while (array[j] > pivot) {
j--;
}
if (i <= j) {
swap(array, i, j);
i++;
j--;
}
}
return i;
};
// Execute code block here
var array2 = new createNonSortedRandomArray(33);
console.log(array2.toString());
array2.quickSort();
console.log(array2.toString());`
The action ‘NAVIGATE’ with payload {“name”:”Home”} was not handled by any navigator. Do you have a screen named ‘Home’?
I’m using the React NavigationV6 to create a static app for now.
After setting up my Navigation process like this Im having an issue moving to the Home Screen from the Login and Register Screen. And also the Home screen is not rendering the Bottom Tab which is meant to show icons.
I did it this way
package.json
"@react-native-community/masked-view": "^0.1.11",
"@react-native-masked-view/masked-view": "^0.2.6",
"@react-navigation/bottom-tabs": "^6.0.9",
"@react-navigation/material-bottom-tabs": "^6.0.9",
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
"@react-navigation/stack": "^6.0.11",
"axios": "^0.24.0",
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-confirmation-code-field": "^7.2.0",
"react-native-gesture-handler": "~2.1.0",
"react-native-paper": "^4.11.2",
"react-native-reanimated": "~2.3.1",
"react-native-safe-area-context": "3.3.2",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "~3.10.1",
"react-native-vector-icons": "^9.0.0",
"react-native-web": "0.17.1",
"react-redux": "^7.2.6"
App.js
import React from "react";
import RootNavigation from './src/navigation/RootNavigation';
export default function App() {
return (
<RootNavigation/>
);
}
RootNavigation.js
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import AuthNavigation from "./AuthNavigation";
const RootNavigation = () => {
return (
<SafeAreaProvider>
<NavigationContainer>
<AuthNavigation />
</NavigationContainer>
</SafeAreaProvider>
);
};
export default RootNavigation;
AuthNavigation.js
import React from "react";
import { createStackNavigator } from "@react-navigation/stack";
// Screens
import Onboarding from "../screens/Auth/Onboarding";
import Login from "../screens/Auth/Login";
import Register from "../screens/Auth/Register";
import VerifyCode from "../screens/Auth/VerifyCode";
import ForgotPassword from "../screens/Auth/ForgotPassword";
import MainTabNavigation from "../navigation/MainTabNavigation";
const Stack = createStackNavigator();
const AuthNavigation = () => {
return (
<Stack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName="Onboarding"
>
<Stack.Screen name="Onboarding" component={Onboarding} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="VerifyCode" component={VerifyCode} />
<Stack.Screen name="ForgotPassword" component={ForgotPassword} />
<Stack.Screen name="MainTabNavigation" component={MainTabNavigation} />
</Stack.Navigator>
);
};
export default AuthNavigation;
MainTabNavigation.js
import React from "react";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import { createMaterialBottomTabNavigator } from "@react-navigation/material-bottom-tabs";
import HomeStackNavigation from "../navigation/HomeStackNavigation";
import WalletStackNavigation from "../navigation/WalletStackNavigation";
import HistoryStackNavigation from "../navigation/HistoryStackNavigation";
import ProfileStackNavigation from "../navigation/ProfileStackNavigation";
const Tab = createMaterialBottomTabNavigator();
const MainTabNavigation = () => {
return (
<Tab.Navigator
initialRouteName="Home"
activeColor="#e91e63"
barStyle={{ backgroundColor: "tomato" }}
>
<Tab.Screen
name="Home"
component={HomeStackNavigation}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={24} />
),
}}
/>
<Tab.Screen
name="Wallet"
component={WalletStackNavigation}
options={{
tabBarLabel: "Wallet",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={black} size={24} />
),
}}
/>
<Tab.Screen
name="History"
component={HistoryStackNavigation}
options={{
tabBarLabel: "History",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="bell" color={color} size={24} />
),
}}
/>
<Tab.Screen
name="Profile"
component={ProfileStackNavigation}
options={{
tabBarLabel: "Profile",
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="account" color={color} size={24} />
),
}}
/>
</Tab.Navigator>
);
};
export default MainTabNavigation;
HomeStackNavigation.js
import React from "react";
import { createStackNavigator } from "@react-navigation/stack";
import Home from "../screens/Home/Home";
import Wallet from "../screens/Home/Wallet/Wallet";
import History from "../screens/Home/History/History";
import Profile from "../screens/Home/Profile/Profile";
const HomeStack = createStackNavigator();
const HomeStackNavigation = () => {
return (
<HomeStack.Navigator>
<HomeStack.Screen name="Home" component={Home} />
<HomeStack.Screen name="Wallet" component={Wallet} />
</HomeStack.Navigator>
);
};
export default HomeStackNavigation;
WalletStackNavigation.js
import React from "react";
import { createStackNavigator } from '@react-navigation/stack';
import Wallet from "../screens/Home/Wallet/Wallet";
const WalletStack = createStackNavigator();
const WalletStackNavigation = () => {
return (
<WalletStack.Navigator>
<WalletStack.Screen name="Wallet" component={Wallet} />
</WalletStack.Navigator>
);
};
export default WalletStackNavigation;
Login.js
import React, { useState } from "react";
import {
StyleSheet,
View,
Text,
Image,
TouchableOpacity,
TextInput,
} from "react-native";
const Login = (props) => {
const [email, setEmail] = useState();
const [password, setPassword] = useState();
return (
<View style={styles.container}>
<View style={styles.textContainer}>
<View style={styles.backButtonContainer}>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Image
source={require("../../../assets/images/back-arrow.png")}
style={styles.backButton}
/>
</TouchableOpacity>
</View>
<Text style={styles.text}>Let's sign you in!</Text>
<Text style={styles.textTwo}>Welcome back. You've been missed!</Text>
</View>
<View style={styles.registerFormContainer}>
<View style={styles.textInputContainer}>
<TextInput
style={styles.textInput}
onChangeText={setEmail}
value={email}
placeholder="Email"
/>
</View>
<View style={styles.textInputContainer}>
<TextInput
style={styles.textInput}
onChangeText={setPassword}
value={password}
placeholder="Password"
/>
</View>
<TouchableOpacity style={styles.forgotPasswordButton} onPress={() => navigation.navigate("ForgotPassword")}>
<Text style={styles.forgotPasswordText}>Forgot Password?</Text>
</TouchableOpacity>
<View style={styles.buttonContainer}>
<TouchableOpacity
style={styles.button}
onPress={() => props.navigation.navigate("Home")}
>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>
<View style={styles.haveAnAccount}>
<Text>
Dont Have an Account?
<Text
style={styles.haveAnAccountText}
onPress={() => props.navigation.navigate("Register")}
>
{" "}
Create One
</Text>
</Text>
</View>
</View>
</View>
);
};
export default Login;
How to import certain node module version?
How would you import a specific version of a node module? I know in npm
you can do npm i [email protected]
But whats not what I’m looking for. I so far I have like this:
// File 1
const fetch = require('[email protected]');
// File 2
const fetch = require('[email protected]');
Any help would be appreciated. Thank you.
Refactor custom route component after updating react-router-dom
I am working on a project, using this boilerplate https://github.com/ankushjain2001/fastapi-react-mongodb and updated the dependencies for the frontend to new major versions.
I already fixed some errors, but cant get custom routes refactored properly..
This is how it is used in the App.js
<ProtectedRoute path="/admin" exact strict component={Home} />
And this is the Component itself
export const ProtectedRoute = ({component: Component, ...rest}) => {
return (
<Route
{...rest}
render={props => {
// Goto the concerned route when authenticated
if (auth.isAuthenticated()){
return <Component {...props}/>
}
// Goto the default login page when not authenticated
else {
return (
<div>
<Landing {...props}/>
</div>
)
}
}}
/>
);
};
The error I am getting is:
Uncaught Error: [ProtectedRoute] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
How can i fix this? Thanks in advance 🙂
React bootstrap carousel not showing static video but audio is working, slides are present
import React from 'react';
import Carousel from 'react-bootstrap/Carousel';
import 'bootstrap/dist/css/bootstrap.min.css';
import { videoCarouselData } from './carouselData';
import Video from './Video';
const VideoCarousel = () => {
return (
<Carousel>
{videoCarouselData.map((videoItem, index) => {
return (
<Carousel.Item key={index}>
<Video video={videoItem.video} title={videoItem.title} />
<Carousel.Caption>
<h3>{videoItem.title}</h3>
<p>{videoItem.detail}</p>
</Carousel.Caption>
</Carousel.Item>
);
})}
</Carousel>
);
};
export default VideoCarousel;
This is the react bootstrap video carousel
import React from 'react';
import { VideoContainer, VideoFile, VideoWrapper } from './VideoElements';
import Vid1 from '../../res/video/Alostro.mp4';
const Video = ({ video, title }) => {
return (
<>
<VideoContainer>
<VideoWrapper>
<VideoFile
width='560'
height='315'
src={video}
title={title}
frameborder='0'
allowFullScreen
/>
{console.log(video)}
</VideoWrapper>
</VideoContainer>
</>
);
};
export default Video;
import styled from 'styled-components';
export const VideoContainer = styled.div`
position: relative;
overflow: hidden;
padding-top: 56.25%;
/* width: 100vw;
height: 100vh; */
`;
export const VideoWrapper = styled.div`
position: relative;
/* padding-bottom: 56.25%; 16:9 */
height: 0;
`;
export const VideoFile = styled.iframe`
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: translate(-50%, -50%);
border:0;
@media (min-aspect-ratio: 16/9) {
/* height = 100 * (9 / 16) = 56.25 */
height: 56.25vw;
}
@media (max-aspect-ratio: 16/9) {
/* width = 100 / (9 / 16) = 177.777777 */
width: 177.78vh;
}
`;
Video component and styling
import React from 'react';
import PictureCarousel from '../Components/PictureCarousel/PictureCarousel';
import { pictureCarouselData } from '../Components/PictureCarousel/pictureCarouselData';
import VideoCarousel from '../Components/VideoCarousel/Carousel';
import { videoCarouselData } from '../Components/VideoCarousel/carouselData';
import Video from '../Components/VideoCarousel/Video';
const Home = () => {
return (
<>
<VideoCarousel />
{/* <Video /> */}
{/* <PictureCarousel slides={pictureCarouselData} /> */}
</>
);
};
export default Home;
Where video carousel will be rendered.
Where the video carousel is rendered
So I’m trying to create a video carousel using react bootstrap carousel. the videos do not show up but from dev tools i can see the carousel item is there and is in fact working, the audio even plays, but the videos do not show.
How do I a space between elements of flatMap function?
I am putting together a Pokédex application for a school project.
My tutor suggested I use a flatMap function to display pokémon types and abilities as there is sometimes more than one.
However, they just get listed with commas between them and no spacing. I’d like to add some spacing between the pokémon types. Can anyone help me with how to do that?
Code below:
function loadDetails(pokemon) {
let url = pokemon.detailsUrl
return fetch(url)
.then(function (response) {
return response.json()
})
.then(function (details) {
pokemon.imageUrl = details.sprites.front_default
pokemon.height = details.height
pokemon.weight = details.weight
pokemon.abilities = details.abilities.flatMap(
(element) => element.ability.name
)
pokemon.types = details.types.flatMap(
(element) => element.type.name
)
})
.catch(function (e) {
console.error(e)
})
}