Array variable inside .setImage() doesn’t work. discord.js

I am trying to get my bot to send and embed and I want the gif to change each time, but for some reason when I put the array variable inside the .setImage() it doesn’t work. The message is sent, but its just missing a picture. Here is my code.

var string1 = message.content.substring(6);
        let channel = message.channel;
        var Gifs = ['https://media.giphy.com/media/yUzMZZWrU6aZy/giphy.gif', "https://th.bing.com/th/id/R.e2cf7c01031a331ccef83051a973ea9e?rik=9NSxT6EyIBiNfw&riu=http%3a%2f%2fgifimage.net%2fwp-content%2fuploads%2f2017%2f07%2fanime-slap-gif-13.gif&ehk=Z1bcjra0ue2IWQAqeic6ZrIkMFS6Hxcvk%2boKlN5TPF4%3d&risl=&pid=ImgRaw&r=0", "https://media1.tenor.com/images/f619012e2ec268d73ecfb89af5a8fb51/tenor.gif?itemid=8562186", "https://media.giphy.com/media/L7iHfUrBk3cqY/giphy.gif", "https://gifimage.net/wp-content/uploads/2017/07/anime-slap-gif-12.gif"];
        var anim = Math.floor(Math.random() * 5);
        var anims = anim[Gifs];
        const exampleEmbed = new Discord.MessageEmbed()
          .setColor('#04785f')
          .setTitle('Instant Replay:')
          .setImage(anims)
          .setTimestamp()
        console.log(string1)
        message.channel.send('You slapped: ' + string1);
        channel.send(exampleEmbed);

Here is what it returns

Auto click function in Javascript

I am trying to automatically click a button through javascript when the page is loaded. I do not have access to HTML file; therefore, I have to fetch the class of the button and implement through javascript. I have tried many things, even tried to import jQuerry in JS file but nothing seems to work.

Error 1) If I call click function solely on JS than it gives error that click is not defined
Error 2) If I import jQuerry and use built in function, it gives error of ‘$’ not defined.

Here is the code

// //Save Draft trigger
// var draft = await document.getElementsByClassName('Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92')
// draft.click();
//document.querySelectorAll('Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').click();
// window.onload = function(){
//     var draft = document.querySelectorAll('.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92');
//     draft.click();
//     //document.querySelectorAll('.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').dispatchEvent(new MouseEvent("click"));
//     //document.querySelectorAll('.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').dispatchEvent(new MouseEvent("click"))
//     // setInterval(function(){
//     //     draft.click();
//     // },1000);  // clicks again every 1000 miliseconds
// }
document.head.innerHTML += "<script src='https://code.jquery.com/jquery-3.6.0.min.js' integrity='sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=' crossorigin='anonymous'></script>"

var script = document.createElement('script');
var x = setInterval(function(){ 
    if(typeof jQuery !== 'undefined'){ 
        // do your stuff 
        $(document).ready(function(){
            $('.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').trigger('click');
          });
    } else {
        console.log('it did not work')
    }
}, 50);


// script.src = 'https://code.jquery.com/jquery-3.6.0.min.js';
// script.type = 'text/javascript';
// document.getElementsByTagName('head')[0].appendChild(script);
// var waitForLoad = function () {
//     if(typeof jQuery != "undefined"){
//         $.get("myfile.php")
//     } else{
//         window.setTimeout(waitForLoad, 1000)
//     }
// }
// window.setTimeout(waitForLoad, 1000)
// $(document).ready(function(){
//     $('.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').trigger('click');
//   });


// var draft = document.querySelectorAll('.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92');
//     draft.click();
//document.getElementsByClassName('Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').click();
//document.querySelector('button.Button_button__1HmfN Button_primary__7rvYY Button_inline__3k2so Button_truncated__3pQ92').click();

//console.log(title);
//console.log(product.title);

How to pass backgroundColor as props in inputContainerStyle in Input component react native elements

               const AppInput = (_props: InputProps) => {

                  return(
                         <Input
                         labelStyle={styles.labelStyle}
                         inputContainerStyle={[
                         styles.inputContainerStyle,
                         {
                          borderColor: _props.placeholderTextColor,
                          borderWidth: isFocus ? 1 : 0,
                          borderBottomWidth: isFocus ? 1 : 0,
                          backgroundColor: Props.backgroundColor, //in this line i want to 
                                                        pass props from parents component

                          },
                          ]}
                          inputStyle={styles.inputStyle}

                         autoCompleteType="phone"
                         {..._props}
                         errorStyle={styles.errorStyle}
                         onFocus={() => onFocus(true)}
                         onBlur={onBlur}
                         />
                      )
                    }

Through parents components

                       <AppInput
                      placeholder={
                      isExculde ? "Don't show recipes with..." : 'Prefer recipes with...'
                       }
                        placeholderTextColor={ isExculde ? colors.icon.danger : 
                          colors.inputSetting.success
                         }
                         keyboardType="default"
                      rightIcon={
                         <Icon
                         name="search"
                         size={24}
                         color={
                             isExculde ? colors.icon.danger : colors.inputSetting.success
                               }
                        tvParallaxProperties={undefined}
                         containerStyle={{right: 8}}
                         />
                          }
                       onChangeText={e => setShowExcludeList()}
    
                      inputContainerStyle={{backgroundColor:"red"}}
                      />

when i pass inputContainerStyle from parent componet its override the default style from Input component , i just want to pass backgroundcolor but not override default styles.

A/B test adjustment only visible on new page view

During the A/B tests that I start, I often see the following happening:

I open a page that is part of the A/B test and do NOT see the variation change
I refresh the page and see the change, so I was in the variant
So it seems that I don’t see the change in the variant immediately, but only after I refresh the page again. So I never immediately enter the variant when I come to the website.

It all works fine in the debug mode of Google Optimize.

I have the Activation Event set to ‘On page load’, but maybe I should work with ‘On custom event’?

want to convert class component into functional component it has two render method so i am confused how to convert it

import React from "react";
import { render } from "react-dom";
import Chart from "./Chart";
import { getData } from "./utils";

import { TypeChooser } from "react-stockcharts/lib/helper";
import { useEffect, useState } from "react/cjs/react.production.min";

class ChartComponent extends React.Component {
    componentDidMount() {
        getData().then(data => {
            this.setState({ data })
        })
    }
    render() {
        if (this.state == null) {
            return <div>Loading...</div>
        }
        return (
            <TypeChooser>`enter code here`
                {type => <Chart type={type} data={this.state.data} />}
            </TypeChooser>
        )
    }
}

render(
    <ChartComponent />,
    document.getElementById("root")
);

the above mention i want to convert the class component into functional component i tried but its not running may be it has two render method
the above code is from index.js file
now the below mentioned code is Chart.js which is imported in index.js

import React from "react";
import PropTypes from "prop-types";

import { scaleTime } from "d3-scale";
import { utcDay } from "d3-time";

import { ChartCanvas, Chart } from "react-stockcharts";
import { CandlestickSeries } from "react-stockcharts/lib/series";
import { XAxis, YAxis } from "react-stockcharts/lib/axes";
import { fitWidth } from "react-stockcharts/lib/helper";
import { last, timeIntervalBarWidth } from "react-stockcharts/lib/utils";

class CandleStickChart extends React.Component {
    render() {
        const { type, width, data, ratio } = this.props;
        console.log("type===>",type);
        const xAccessor = d => d.date;
        const xExtents = [
            xAccessor(last(data)),
            xAccessor(data[data.length - 100])
        ];
        return (
            <ChartCanvas height={400}
                    ratio={ratio}
                    width={width}
                    margin={{ left: 50, right: 50, top: 10, bottom: 30 }}
                    type={type}
                    seriesName="MSFT"
                    data={data}
                    xAccessor={xAccessor}
                    xScale={scaleTime()}
                    xExtents={xExtents}>

                <Chart id={1} yExtents={d => [d.high, d.low]}>
                    <XAxis axisAt="bottom" orient="bottom" ticks={6}/>
                    <YAxis axisAt="left" orient="left" ticks={5} />
                    <CandlestickSeries width={timeIntervalBarWidth(utcDay)}/>
                </Chart>
            </ChartCanvas>
        );
    }
}

CandleStickChart.propTypes = {
    data: PropTypes.array.isRequired,
    width: PropTypes.number.isRequired,
    ratio: PropTypes.number.isRequired,
    type: PropTypes.oneOf(["svg", "hybrid"]).isRequired,
};

CandleStickChart.defaultProps = {
    type: "svg",
};
CandleStickChart = fitWidth(CandleStickChart);

export default CandleStickChart;

Now i want to convert these two files in functional base

how to change submenu arrow icon according to the menu display

this is the my menu

<ul>
  <li class="nav-item">
                <a class="nav-link sub-parent">
                    <i class="nav-icon fas fa-tachometer-alt"></i>
                    <p>
                        Dashboard
                        <i class="right fas fa-angle-left"></i>
                    </p>
                </a>
                <ul class="nav sub-menu">
                    <li class="nav-item">
                        <a href="../../index.html" class="nav-link">
                            <i class="far fa-circle nav-icon"></i>
                            <p>Dashboard v1</p>
                        </a>
                    </li>
                </ul>
            </li>
</ul>

this is the jquery function that i use for sub menu

    $(document).ready(function(){
    $('.sub-parent').click(function(e){
      e.preventDefault();
      $(this).next('.sub-menu').slideToggle();
    });
  });

css class

 .sub-menu{display: none;}

Currently left arrow icon display in the menu. I used this for it

when sub menu open, i need to change this icon. How i do it.?

Cannot find file: ‘Chart.js’ does not match the corresponding name on disk: ‘.node_moduleschart.jsdistchart.js’

i am trying to impliment a bar chart what am i doing wrong here?

here also i am getting error saying to use typescript

formatter: (value: number) => value + " %",
but i use only .js format

import { Chart } from "chart.js";

import { Bar } from "react-chartjs-2";
import ChartjsPluginStacked100 from "chartjs-plugin-stacked100";
import "chart.js/auto";
import ChartDataLabels from "chartjs-plugin-datalabels";
Chart.register(ChartDataLabels);

const ExampleChart = () => (
  <Bar
    data={{
      labels: ["January", "February", "March", "April", "May", "June", "July"],
      datasets: [
        {
          label: "My First dataset",
          backgroundColor: "#EC932F",
          borderColor: "rgba(255,99,132,1)",
          borderWidth: 1,
          hoverBackgroundColor: "rgba(255,99,132,0.4)",
          hoverBorderColor: "rgba(255,99,132,1)",
          data: [65, 59, 80, 81, 56, 55, 100],
          borderRadius: 50, // Make Rectangle rounded
        },
      ],
    }}
    options={{
      indexAxis: "y", // Horizontal bar
      plugins: {
        datalabels: {
          formatter: (value: number) => value + " %", // Add the percentage after the value
          align: "end",
          anchor: "end",
          clip: true, // Hide label if outside of the chart
        },
      },
      scales: {
        x: {
          grid: {
            display: false, // Hide x grid
          },
        },
        y: {
          grid: {
            display: false, // Hide y grid
          },
        },
      },
    }}
  />
);

export default function bar() {
  return (
    <div className="">
      <ExampleChart />
    </div>
  );
}

How to authenticate windows user in a intranet Nodejs app

I am new here.

I developed a webapp using React and NodeJS for the company I am working at. I setup authenticacion using JWT (Using a login HTML form) but now I am required to authenticate users in the webapp using the windows credential. I am hosting the React app in IIS in a server inside the company local network.

What are the options to get this task done? Thanks for your comments.

I have tried Passport-windowsauth.

C# host with Chrome Native Messaging Extension

I am trying to get Native Messaging between my chrome extension and my c# application. But below are my questions :

  1. How to open only one Native app at a time ?. Clicking on the extension again will open the Native app again & again.

  2. Can I communicate with an already open native app?

I built my extension and native app using the code in the following question.

Native Messaging Chrome

How do I display different web pages with differing subject on one page

Supposing I have contents stored in a database, how do I display them differently on one React Page I’m using MERN.
I provided an mock up example of what I want to do.

varying page layout for varying page subject

<body>
<article className='content' ref={content}>
  {content.map((content) => {
    const { title, image, text } = content;
    return (
      <article>
        <h3>{title}</h3>
        <img>{image}</img>
        <p >{text}</p>
        <div class="infocontainer">{info}</div>
      </article>
    );
  })}
 </article>;
</body>

someone said I should do this based on the code above via REACT ROUTER. but, its not quite what I need. I need each page to be different from any page I make. because making every subject structured exactly the same from any other is not the best approach in my opinion.

Styling an html tag inside javascript file

How can i add a background color to each element on hover to this dropdown list?

            ${surahs.map(s => `<option value="${s.id}"> ${s.id} : ${s.name_arabic} - ${s.name_simple}</option>`).join('n')}

HTML:

          <a href="#" id="surah-DropDown" onchange="onSurahChange(this.value)"></a>

I tried to add it in the css file through .surahdropdown but failed, because it gave a background color to the whole list on hover instead of each element

nextjs getStaticProps() giving an Error: Image is missing required “src” with next/image

From reading the nextjs documentation the getStaticProps should pre-render data that I want before a user comes to my site. I am trying to get images before I load them onto cards.

Here in my index.js

 export async function getStaticProps() {
    const images = getImages();
    return {
        props: {
            data: await Promise.all(images), // wait for all images to load
        }, revalidate: 5
    };
}

The getImages function looks like this

export function getImages() {
    const frameCount = 39;
    const data = [];
    for (let id = 0; id <= frameCount; id++) {
        // add new promise to array
        data.push(
            fetch(`http://localhost:3000/GeneratedImgs/${id}.png`).then(
                (res) => res.url
            )
        );
    }
    return data;
}

So then in the index.js I pass that data into a component which passes it into another component to the next/image.

export default function Home({ data }) {
    
    let testCardGrid = <div className="loading"></div>;
    if (data !== null) {
        mouseCardGrid = <CardGrid data={data} />;
    }

    return (
        <>
            <Head>
                <title>Mouse</title>
                <meta name="description" content="Generated by create next app" />
                <link rel="icon" href="/favicon.ico" />
            </Head>

            <Header />
            {testCardGrid}
            <Map />
        </>
    );
}

CardGrid.js looks like this:

export default function CardGrid({ data }) {
    let cardArray = [];
    let randomNumbers = [];

    function getRandomInts(quantity, max) {
        const arr = [];
        while (arr.length < quantity) {
            var candidateInt = Math.floor(Math.random() * max) + 1;
            if (arr.indexOf(candidateInt) === -1) arr.push(candidateInt);
        }
        return arr;
    }

    randomNumbers = getRandomInts(8, 40);
    randomNumbers.forEach((num) => {
        cardArray.push({
            title: `Card#${num}`,
            imageUrl: data[num]
        });
    });

    useEffect(() => {
        console.log("cardgrid triggered");
    }, []);
    return (
        <section id="content" className="section-padding">
            <div className="container-fluid">
                <div className="row">
                    {cardArray.map((object) => (
                        <Card title={object.title} imageUrl={object.imageUrl} />
                    ))}
                </div>
            </div>
        </section>
    );
}

Finally the Card.js file looks like this:

export default function Card({ title, imageUrl }) {
    useEffect(() => {
        console.log("card added");
    }, []);

    return (
        <div className="col-lg-3 col-sm-6">
            <div className="card text-center">
                <Image
                    priority
                    className="card-img-top"
                    src={imageUrl}
                    height={300}
                    width={300}
                />

                <div className="card-body">
                    <h2 className="card-text">{title}</h2>
                </div>
            </div>
        </div>
    );
}

After I refresh the page a couple of times or when I go to a differnt page on the site and come back to the home page it will give me the error:

Unhandled Runtime Error
Error: Image is missing required “src” property. Make sure you pass “src” in props to the next/image component. Received: {“width”:300,”height”:300}

I was trying to show a loading div if the data was null and thought I could try the revalidate attribute the getStaticProps() method has but it too was giving me the same error.

So, I am not sure I understand this because I thought that the getStaticProps would always get the images before the page loads. I see in the docs that it says it runs under next build. So is it just once and done? Am I missing a fundamental concept of pre-rendering? please give me your advice.

Adding custom javascript to my Shopify Section, which toggles a pop, not working?

I am trying to add custom javascript to my Shopify Section, which toggles a pop. I have created a button, which when clicked toggles a function. This function then toggles the specific div to be displayed/hidden. The styling shows up on the page, but the javascript does not seem to work?

<html>
<head>


<style>
#myDIV {
  width: 100%;
  padding: 50px 0;
  text-align: center;
  background-color: lightblue;
  margin-top: 20px;
}
</style>
  
<script>
  
function myFunction() {
  var x = document.getElementById("myDIV");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
  
</script>
  
</head>
<body>

<button onclick= "myFunction()" >Click it</button>

<div id="myDIV">
This is my DIV element.
</div>

</body>
</html>

{% schema %}
{
  "name": "Scan",
  "settings": [
    {
      "id": "link",
      "type": "url",
      "label": "Button link"
    },
    {
      "id": "linktext",
      "type": "text",
      "label": "Button text",
      "default": "Scan"
    }
  ]
  ,
  "presets": [
    {
      "name": "Scan",
      "category": "Scan"
    }
  ]
}

{% endschema %}

How do I show or hide a column in one table when a column in another table is being hovered over?

I’m working on a webpage showing election results, and I want it to switch from a raw vote map to a percentage map when a percentage is hovered over, using different values for the same key. Changing out the maps is an entirely separate issue, mind, but right now I want to switch out the key labels. The relevant code is currently:

<div id='towninfo'>
    <div id='candidates'>
    <table id='results'>
        <tr>
            <th>Candidate</th>
            <th colspan='2'>Votes</th>
        </tr>
        <tr style='font-weight: bold'>
            <td class='cand' id='cand1'>Candidate 1 &#10004;</td>
            <td class='votes' id='votes1'>100</td>
            <td class='percent' id='pct1'>50%</td>
        </tr>
        <tr>
            <td class='cand' id='cand2'>Candidate 2</td>
            <td class='votes' id='votes2'>60</td>
            <td class='percent' id='pct2'>30%</td>
        </tr>
        <tr>
            <td class='cand' id='cand3'>Candidate 3</td>
            <td class='votes' id='votes3'>40</td>
            <td class='percent' id='pct3'>20%</td>
        </tr>
    </table>
    </div>
</div>
<div id='key'>
    <table>
        <tr>
            <th>Color</th>
            <th class='count'>Votes</th>
            <th class='pctkey'>Percent</th>
        </tr>
        <tr>
            <td class='color' style='background-color: rgb(91, 89, 84);'></td>
            <td class='count'>41-50</td>
            <td class='pctkey'>100%</td>
        </tr>
        <tr>
            <td class='color' style='background-color: rgb(120, 114, 99);'></td>
            <td class='count'>31-40</td>
            <td class='pctkey'>75-100%</td>
        </tr>
        <tr>
            <td class='color' style='background-color: rgb(164, 151, 122);'></td>
            <td class='count'>21-30</td>
            <td class='pctkey'>50-75%</td>
        </tr>
        <tr>
            <td class='color' style='background-color: rgb(200, 186, 153);'></td>
            <td class='count'>11-20</td>
            <td class='pctkey'>25-50%</td>
        </tr>
        <tr>
            <td class='color' style='background-color: rgb(223, 216, 197);'></td>
            <td class='count'>1-10</td>
            <td class='pctkey'>0-25%</td>
        </tr>
        <tr>
            <td class='color' style='background-color: rgb(255, 255, 255);'></td>
            <td class='count'>0</td>
            <td class='pctkey'>0%</td>
        </tr>
    </table>
</div>

What I need to do is make it so that, by default, the ‘pctkey’ class is hidden, but when the cursor is over anything in the ‘percent’ class, the ‘pctkey’ class is shown and the ‘count’ class is hidden. How do I do this? I already have a Javascript page for displaying the map, so I’m not specifically looking for a CSS option.

I tried using “.percent:hover + .pctkey” in the CSS file like various guides have shown, but nothing happens.