I'm working on a randominteger slash command in discord.js
It supposed to work like this :
Discord User : /randominteger minimal:1 maximal:10
Bot : (embed)
Random number
4
1 - 10
But instead the bot just says "This interaction failed"
I don't know why the bot says that though.
Can someone explain how it happened and how to fix it?
const { SlashCommandBuilder, SlashCommandStringOption } = require('#discordjs/builders');
const { MessageEmbed } = require('discord.js')
const color = "#ffed47"
module.exports = {
data: new SlashCommandBuilder()
.setName('randominteger')
.setDescription('Replies with a random integer!')
.addIntegerOption(option =>
option.setName('minimal')
.setDescription('The minimal integer for the random integer')
.setRequired(true))
.addIntegerOption(option =>
option.setName('maximal')
.setDescription('The maximal integer for the random integer')
.setRequired(true)),
async execute(interaction) {
const minimal = interaction.options.getInteger("minimal")
const maximal = interaction.options.getInteger("maximal")
minimal = Math.ceil(minimal)
maximal = Math.floor(maximal)
const randomNumber = Math.floor(Math.random() * (maximal+0.1 - minimal) + minimal);
const random = new MessageEmbed()
.setColor(color)
.setTitle("Random Number")
.setDescription(String(randomNumber))
.setFooter(String(minimal) + " - " + String(maximal))
await interaction.reply({embeds : [random]})
},
};
Sorry, I just didn't implement the the command properly xd
It worked.. with a 1 thing, you need to change the minimal and maximal variable to "var" not "const" (so the minimal and maximal variable can be used)
Related
i am having a problem that whenever i type the +warn <#user> then everything goes well , lets take an example that i want to warn any user so i'll type +warn <#user> and then it will show a embed by saying that your are banned by this this and you are banned from this this and also shows that how many warns the user now have and lets also take that he have 1 warn till now, and now warn another user by typing +warn <#user> and then it will show the thing blah blah blah but.. when the bot shows that how many warns the second user have then it will show the same value of warn as the first user like this warns(of the first user): 1 but when with the second user it shows warns(of the second user): 2 and even the second user have 0 warns but it will show 2 and when you retry to warn the first user it will show 3 warns idk why
code:-
const config = require("../config.json");
const Database = require("#replit/database")
const db = new Database()
const { MessageEmbed, username } = require('discord.js')
exports.run = async (client, message, args, Discord) => {
let reason = args.slice(1).join(" ")
if (!reason) reason = "No reason provided"
const user = message.author.id
let warns = await db.get(`warns_${message.author.id}`)
let member = message.mentions.members.first()
if (!member) return message.reply("Please mention a user to warn")
const wembed = new MessageEmbed()
.setTitle(`You have been warned`)
.setDescription(`You have been warned by ${message.author.username}\nFrom the server of: ${message.guild.name}\nWith the reason: ${reason}\nNow you have ${warns} warns`)
if (!member === member.user.bot) {
member.send({embeds: [wembed]})
} else {
message.channel.send(`unable to send dm to ${member}`)
}
const embed = new MessageEmbed()
.setTitle(`Warn to ${member}`)
.setDescription(`${member} has been warned successfully warned\n\n${member} have now ${warns}\nReason: ${reason}`)
message.channel.send({embeds: [embed]})
await db.set(`warns_${message.author.id}`, warns + 1)
member.send({embeds: [wembed]})
}
exports.conf = {
aliases: ['warning']
};
exports.help = {
name: "warn"
};```
in a scenario, WalletA is receiving TokenB in a regular basis from AddressC.
AddressC only sends TokenB, nothing else.
in etherscan or bscscan it is simple to see how much of TokenB is received in WalletA and "from" field is there so you can do some math to get total.
How can this be done using web3? I couldn't find any relevant api call in web3 documents.
I can get total balance of TokenB in WalletA by web3.js but I need the count of tokens only sent from AddressC.
Thanks.
As per the ERC-20 standard, each token transfer emits a Transfer() event log, containing the sender address, receiver address and token amount.
You can get the past event logs using the web3js general method web3.eth.getPastLogs(), encode the inputs and decode the outputs.
Or you can supply ABI JSON of the contract (it's enough to use just the Transfer() event definition in this case) and use the web3js method web3.eth.Contract.getPastEvents(), which encodes the inputs and decodes the outputs for you based on the provided ABI JSON.
const Web3 = require('web3');
const web3 = new Web3('<provider_url>');
const walletA = '0x3cd751e6b0078be393132286c442345e5dc49699'; // sender
const tokenB = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; // token contract address
const addressC = '0xd5895011F887A842289E47F3b5491954aC7ce0DF'; // receiver
// just the Transfer() event definition is sufficient in this case
const abiJson = [{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}];
const contract = new web3.eth.Contract(abiJson, tokenB);
const fromBlock = 10000000;
const toBlock = 13453500;
const blockCountIteration = 5000;
const run = async () => {
let totalTokensTranferred = 0;
for (let i = fromBlock; i <= (toBlock - blockCountIteration); i += blockCountIteration) {
//console.log("Requesting from block", i, "to block ", i + blockCountIteration - 1);
const pastEvents = await contract.getPastEvents('Transfer', {
'filter': {
'from': walletA,
'to': addressC,
},
'fromBlock': i,
'toBlock': i + blockCountIteration - 1,
});
}
for (let pastEvent of pastEvents) {
totalTokensTranferred += parseInt(pastEvent.returnValues.value);
}
console.log(totalTokensTranferred);
}
run();
I want to make a image embed via arguments, but I can't set the Title of the embed.
But when I try to run the comand, it errors out and the embed won't appear
if(message.content.startsWith(prefix + "foto-annuncio"))
{
if(!message.member.hasPermission(["MANAGE_MESSAGES"]))
{
/* error message pops out */
}
let argsresult;
let mChannel = message.mentions.channels.first()
message.delete()
argsresult = args.slice(1).join(" ")
let url = args.slice(1).join(" ");
let title = args.slice(2);
message.delete();
const embed = new Discord.RichEmbed ()
.setImage(url)
.setColor('#008000')
.setAuthor('Delta Logistics', 'https://cdn.discordapp.com/attachments/604963851561336832/665504827044003860/zoom_delta_6_discord.png')
.setTitle(title)
mChannel.send(embed).catch(err => console.log(err));
message.channel.send("Done!");
}
As Giuuliopime said you can't set an array as a title, you prob meant to join the arguments:
const title = args.slice(2).join(" ");
so i'm trying this 8ball bot, and everything is working fine, but i can't get how can i leave in the condition that only when the bot get "!verda arg1 arg2" it answers one of the replies in the array.
meanwhile my condition is if the user type the prefix "!verda" only, it replies , i want to include the argument too in the condition
const Discord = require("discord.js");
const client = new Discord.Client();
const cfg = require("./config.json");
const prefix = cfg.prefix;
client.on("message", msg => {
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase;
if (msg.content === prefix){
let replies = [
"Yes.",
"No.",
"I don't know.",
"Maybe."
];
let result = Math.floor((Math.random() * replies.length));
msg.channel.send(replies[result]);
}
else if (msg.content === "!help"){
msg.channel.send("I have only 1 command [!verda]");
}
})
client.login(cfg.token);
const command = args.shift().toLowerCase;
toLowerCase is a function and therefore should be
const command = args.shift().toLowerCase();
By doing msg.content === prefix, you are checking if the whole content of the message is equal to that of cfg.prefix
if(msg.content.startsWith(`${prefix}8ball`) {
}
The answer was simple as i figured it out, i simply had to join the spaces
if (msg.content === `${prefix} ${args.join(" ")}`)
I don't know how to do this and I have been looking for answer but am unable to find it.
if message.content.startswith('^trivia autostart'):
await client.send_message(message.channel, "Game is starting!\n" +
str(player1) + "\n" + str(player2) + "\n" + str(player3) + "\n" +
str(player4) + "\n" + str(player5) + "\n" + str(player6) )
--
I have this code and i'm trying to make it so it when that code gets run that it calls my ^trivia play command without typing it in chat.
Is this possible?
The solution to that would be defining functions for each command you need to be called globally by your bot. Take the following example:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('error' => console.log);
bot.on('message', message => {
let prefix = '!';
let sender = message.author;
let msg = message.content;
let cont = msg.split(' ');
let args = cont.slice(1);
let cmd = msg.startsWith(prefix) ? cont[0].slice(prefix.length).toUpperCase() : undefined;
// Ping function
// can be: function pingCommand () {...}
let pingCommand = () => {
message.channel.send(`Pong!\nTime: ${bot.ping} ms`);
}
// Main command
if (cmd === 'PING') {
pingCommand();
}
// Calling command in another command
if (cmd === 'TEST') {
message.channel.send('Running a ping test on the bot');
pingCommand();
}
});
bot.login(token);
Hope you understand how it would work