Button not working discord.js discord-buttons - javascript

hello so i write this code
module.exports.run = async (Client, message, args, prefix) => {
if (!message.content.startsWith(prefix)) return;
disbut(Client);
let button1 = new disbut.MessageButton()
.setStyle("green") //default: blurple
.setLabel("créer un channel") //default: NO_LABEL_PROVIDED
.setID("create"); //note: if you use the style "url" you must provide url using .setURL('https://example.com')
let button2 = new disbut.MessageButton()
.setStyle("red") //default: blurple
.setLabel("fermer un channel") //default: NO_LABEL_PROVIDED
.setID("close"); //note: if you use the style "url" you must provide url using .setURL('https://example.com')
message.channel.send("Cliquer sur les boutons pour effectuer une action ", {buttons : [button1, button2] });
};
if i execute my command the texte is send in my channel but not the button
and i dont understand why and i dont have any error
thanks for your help :)

In Discord.js v13, the send method only takes a single parameter. Discord.js is only looking at "Cliquer sur les boutons..." and not the second object you are providing.
Instead, use a single MessageOptions object:
message.channel.send({
content: "Cliquer sur les boutons pour effectuer une action ",
buttons: [button1, button2]
});
For more information, see this section in the Discord.js guide.

Related

How to pass a variable from one function to another function CDATA

I am very new to JavaScript.
Here is my problem, I have a form with a "cp" field from which I retrieve the value in real time
This is achieved in a function.
Then I would like to use my result in the mondial relay widget to override the plugin default
After testing several things, I give you my last try which does not show me the "cp" variable in the second function.
So I would like to replace PostCode: "6000" with cp
<input class="form-control" type="text" name="cp" value="" id="cp" required="required" />
<javascript>
var input ;
//le code postal
$(document).ready(function(){
$("#cp").keyup(function(){
const cptest = document.querySelector('[name="cp"]');
console.log (cptest);
var input = document.getElementById("cp").value;
console.log (input);
return input;
});
});
//<![CDATA[
console.log (input);
// Initialiser le widget après le chargement complet de la page
$(document).ready(function () {
// Charge le widget dans la DIV d'id "Zone_Widget" avec les paramètres indiqués
$("#Zone_Widget").MR_ParcelShopPicker({
// Selecteur de l'élément dans lequel est envoyé l'ID du Point Relais (ex: input hidden)
Target: "#Target_Widget",
// Selecteur de l'élément dans lequel est envoyé l'ID du Point Relais pour affichage
TargetDisplay: "#TargetDisplay_Widget",
// Selecteur de l'élément dans lequel sont envoysé les coordonnées complètes du point relais
TargetDisplayInfoPR: "#TargetDisplayInfoPR_Widget",
// BDTEST est utilisé pour les tests => un message d'avertissement apparaît
Brand: "BDTEST ",
// Pays utilisé pour la recherche: code ISO 2 lettres.
Country: "BE",
// Code postal pour lancer une recherche par défaut
PostCode: "6000",
// Activer l'affichage Responsive.
Responsive: true,
// Fonction de callback déclenché lors de la selection d'un Point Relais
OnParcelShopSelected:
AllowedCountries: "FR,BE,NL,LU",
});
});
// ]]>
</javascript>
There are a few issues with your code:
when working with jQuery you should use its powers and not mix it with document.querySelector()
input was declared locally within your jQuery event handler and was therefore invisible.in the global scope
input is only defined properly after the first keyup event (which I changed to input as this also includes mouse based input actions)
var input ;
//le code postal
$(function(){
$("#cp").on("input",function(){
input=this.value;
console.log(input);
// anything you want to happen to
// $("#Zone_Widget").MR_ParcelShopPicker(..)
// needs to happen here ...
});
});
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<input class="form-control" type="text" name="cp" value="" id="cp" required="required" />

My discord bot send the embed message when someone reply something

I'm trying to make the bot only send the embed message when mentioned with #, but it sends again when it's replied.
const mentionEmbed = new Discord.MessageEmbed()
.setColor("#FF5733")
.setTitle("Salve, Roberval na área 🐔")
.setDescription("Sou um bot dedicado ao envio de desenhos ASCII e copypastas utilizados em streams de qualidade duvidosa na plataforma roxa. \n \nPara me usar, basta utilizar o prefixo r! + o comando que você quiser!")
.setFooter("All rights reserved # Roberval - 2021", "https://i.imgur.com/BwCCYT9.jpg");
client.on("message", (message) => {
if (message.author.bot) return false;
if (message.content.includes("#here") || message.content.includes("#everyone")) return false;
if (message.mentions.has(client.user.id)) {
message.channel.send(mentionEmbed);
}
});
Replying to a message mentions the author of the original message, that's why the bot sends the embed
You can check to see if the Message#type property is equal or not to "REPLY".
When you reply to a message, you can choose to mention the user (or not) and by default, it does.
You may want to check if the message is a reply with Message#type equals "REPLY" : https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=type

How to make my Discord.js bot say something when joning a Discord guild?

I want to make my bot send a welcome message when he joins a Guild, but i don't know how, tried to do something but it didn't worked. How can I do that?
Code that not worked:
client.on('guildCreate', guild => {
message.channel.send('¡Hola! Soy el bot de Pepelui85, mi prefix aquí es "*" y mis comandos son: *pc y *llora.');
message.channel.send('¿Encontraste algun bug? Reportalo en el canal desarrollo de mi servidor de Discord.');
message.channel.send('https://discord.gg/3taae9');
});
try do
client.on('guildCreate', guild => {
let SendChannel = guild.channels.get("general") || guild.channels.get("chat");
SendChannel.send('¡Hola! Soy el bot de Pepelui85, mi prefix aquí es "*" y mis comandos son: *pc y *llora.');
Sendchannel.send('¿Encontraste algun bug? Reportalo en el canal desarrollo de mi servidor de Discord.');
SendChannel.send('https://discord.gg/3taae9');
});
or just do this!
client.on('guildCreate', guild => {
let SendChannel = guild.channels.find("name", "general") || guild.channels.find("name", "chat");
if(SendChannel) SendChannel.send('¡Hola! Soy el bot de Pepelui85, mi prefix aquí es "*" y mis comandos son: *pc y *llora. \n¿Encontraste algun bug? Reportalo en el canal desarrollo de mi servidor de Discord. \nhttps://discord.gg/3taae9');
});

Confirm before delete in Sails.js

I'm currently editing a back-end page, but I have a few problems.
I need a confirmation before I delete the Action as you can see I tried this so far but my code is completely skipping the confirm() and only redirects to the index.
Please take a look at the controller code below
delete(req, res, next) {
Action
.findOne(req.param('id'))
.then(({id}) => {
confirm('U staat op het punt een actie te verwijderen, klik op "ok" om hier mee door te gaan');
if(confirm()=== true) {
Action
.destroy(id)
.then(() => {
FlashService.setFlash(req, 'success', 'Action has been deleted')
res.redirect('/answer/index')
})
.catch(err => res.redirect('/answer/index'))
}
})
.catch(err => res.redirect('/answer/index'))
}
}
I also tried console.log to see where my code is stranding but that would only give this error:
Unhandled rejection ReferenceError: confirm is not defined
edit
I tought it also might be usefull to maybe see the HTML so here you go
as you can see the delete is called upon submit maybe I'm doing that extremly wrong but it seems to work besides the confirm mentioned before
<form action="/action/delete/<%= action.id %>" method="POST">
<button type="submit"
class="btn btn-sm btn-icon btn-pure btn-default on-default"
data-toggle="tooltip"
data-original-title="Verwijder"><i class="icon wb-trash" aria-hidden="true"></i>
</button>
</form>
EDIT 2.0
I kind of fixed the problem but still not really I made the following javascript for the delete it's a little basic but that isn't the problem please take a look
<script>
function Delete(){
let c = confirm('U staat op het punt een actie te verwijderen, klik op "ok" om hier mee door te gaan');
if (c){
console.log("done");
window.location.href = "/action/delete/<%= action.id %>"
}
else{
console.log("failed")
window.location.href = "/answer/show/<%= answer.id %>"
}
}
</script>
however, when I go to this page it says "action not defined" but I'm quite sure it is defined to be honest.
I don't really know what I'm doing wrong, any help would be nice
You cannot use the client side confirm javascript on the server side. It does not exist. You should instead call confirm before sending request to the server.
Like so
<button onclick="delete()">Delete</button>
<script>
function delete() {
var confirm = confirm("Do you want to delete?")
if(confirm){
// Call server
}
}
</script>

Function not working properly. Please help

Hello I'm having trouble with the function setUpTranslation().
//The purpose of this function is to place the French phrases into the document and set up the event handlers for the mousedown and mouseup events.
//These are the arrays of the French phrases and English phrases that I have do place into the document:
var english = new Array();
english[0] = "This hotel isn't far from the Eiffel Tower.";
english[1] = "What time does the train arrive?";
english[2] = "We have been waiting for the bus for one half-hour.";
english[3] = "This meal is delicious";
english[4] = "What day is she going to arrive?";
english[5] = "We have eleven minutes before the train leaves!";
english[6] = "Living in a foreign country is a good experience.";
english[7] = "Excuse me! I'm late!";
english[8] = "Is this taxi free?";
english[9] = "Be careful when you go down the steps.";
var french = new Array();
french[0] = "Cet hôtel n'est pas loin de la Tour Eiffel.";
french[1] = "A quelle heure arrive le train?";
french[2] = "Nous attendons l'autobus depuis une demi-heure.";
french[3] = "Ce repas est délicieux";
french[4] = "Quel jour va-t-elle arriver?";
french[5] = "Nous avons onze minutes avant le départ du train!";
french[6] = "Habiter dans un pays étranger est une bonne expérience.";
french[7] = "Excusez-moi! Je suis en retard!";
french[8] = "Est-ce que ce taxi est libre?";
french[9] = "Faites attention quand vous descendez l'escalier.";
//function I'm having trouble with
function setUpTranslation(){
var phrases = document.getElementByTagName("p");
for (i =0; i<phrases.length; i++){
phrases[i].number =i;
phrases[i].childNodes[1].innerHTML =french[i];
phrases[i].childNodes[1].onmousedown =function(){
swapFE(event);
phrases[i].childNodes[1].onmouseup =function(){
swapEF(event);
};
};
}
//Below are the other two functions swapFE() and swapEF(). The purpose of the function swapFE() is to exchange the French phrase for the English translation
//The purpose of the function swapEF() is to exchange the English translation for the French phrase.
function swapFE(e){
var phrase =e.srcElement;
var parent =phrase.parentNode;
var idnum =parent.childNodes[0];
var phrasenum =parseInt(idnum.innerHTML)-1;
phrase.innerText =english[phrasenum];
}
function swapEF(e){
var phrase =e.srcElement;
var parent =phrase.parentNode;
var idnum =parent.childNodes[0];
var phrasenum =parseInt(idnum.innerHTML)-1;
phrase.innerText =french[phrasenum];
}
//Not sure if these are right. Thanks in advance!
Assuming that your HTML looks like this
<p><span>1</span><span></span></p>
<p><span>2</span><span></span></p>
...
<p><span>10</span><span></span></p>
Then all you need to do is to add the curly bracket after swapFE(event); (points for Mr Plunkett) and replace getElementByTagName with getElementsByTagName (you're missing an 's' in there).
One additional thing to note: If the English phrase is shorter than the French, the container might shrink when the onmousedown event fires. If this shrinkage causes the mouse cursor to be positioned outside the container, the subsequent onmouseup event will not be triggered. Of course, if you are using block elements (e.g. a <div>) instead of my assumed <span>, that likely isn't an issue. In any case, it's probably better to attach the event listeners to the <p> tags instead.

Categories

Resources