it's me again, with another new problem!
I'm wanting to make a charge command where you use the menu, but there was an error!
Missing Permissions
If you want to see what's going on, I'll say it's not in slash commands!
gamerole.js
const { MessageActionRow, MessageSelectMenu, MessageEmbed } = require("discord.js")
module.exports = {
name: 'gamerole',
description: "get gaming console roles",
userPerms: ["ADMINISTRATOR"],
run: async(client, message, args, prefix) => {
if(!message.content.startsWith(prefix)) return;
const embed = new MessageEmbed()
.setTitle("Gaming Console Roles")
.setDescription("Get Or Remove Roles By Clicking On Options Given In menu, After Reclicking The Role Will Be Removed, The Bot Will Send DM Message That You Have Added/Removed Roles")
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('gamerole')
.setPlaceholder('Select To Add/Remove Roles')
.addOptions([
{
label: 'XBOX Role',
description: "Click To Add/Remove XBOX Roles",
value: 'xbox',
},
{
label: 'PlayStation Role',
description: "Click To Add/Remove PlayStation Roles",
value: 'playstation',
},
]),
);
await message.channel.send({ embeds: [embed], components: [row]});
}
}
After that I went into messageCreate to see if the problem was there!
messageCreate.js
const db = require("quick.db");
const client = require("../index.js");
client.on('messageCreate', async (message) => {
if(message.author.bot) return;
if(!message.guild) return;
//PER SERVER PREFIX
let prefix = await client.config.prefix;
//1 if (!message.content.startsWith(client.config.prefix)) return;
if(!message.content.startsWith(prefix)) return;
if(!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if(cmd.length == 0 ) return;
let command = client.commands.get(cmd);
if(!command) command = client.commands.get(client.aliases.get(cmd));
if(command) {
//USER PERMS
if(!message.member.permissions.has(command.userPerms || [])) return message.channel.send(`User Dont Have \`${command.userPerms || []}\` Permission`);
//BOT PERMISSIONS
if(!message.guild.me.permissions.has(command.clientPerms || [])) return message.channel.send(`Bot Missing \`${command.botPerms || []}\` Permission`);
}
//EXPORTS TO COMMAND
if(command) command.run(client, message, args, prefix);
});
The error is as follows:
DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/runner/B
ot-beta/node_modules/discord.js/src/rest/Requ
estHandler.js:350:13)
at processTicksAndRejections (node: intern
al/process/task_queues:96:5)
at async RequestHandler.push (/home/runne
r/Bot-beta/node_modules/discord.js/src/rest/R
equestHandler.js:51:14)
at async TextChannel.send (/home/runner/B
ot-beta/node_modules/discord.js/src/structure
s/interfaces/TextBasedChannel.js:175:15) {
method: 'post',
path: '/channels/843914213242961940/message
I
code: 50013,
httpStatus: 403,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [Array],
components: [Array],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 0,
message_reference: [Object],
attachments: undefined,
sticker_ids: undefined
},
files: []
Related
Basically, I'm converting one of my regular commands into a slash command. It's just an embedded response, but the issue is that it says "This interaction failed". I read on deferReply(), but deferReply doesn't work for me at all, it's supposed to say "bot is thinking.." but doesn't. It does the 3 second "Sending command..." then fails.
Code:
const { SlashCommandBuilder, EmbedBuilder } = require('#discordjs/builders');
const wait = require('node:timers/promises').setTimeout;
let questions = [
{
title: "some array you got there!",
},
]
let suggest = ["some array you got there!",]
let q = questions[Math.floor(Math.random()*(questions.length))];
let s = suggest[Math.floor(Math.random()*(suggest.length))];
module.exports = {
data: new SlashCommandBuilder()
.setName('topic')
.setDescription('gives topics'),
async execute(interaction, message) {
interaction.deferReply()
const user = message.mentions.users.first() || message.author;
const embed = {
title: `**${q.title}**`,
author: {
name: 'chat topic:',
icon_url: user.avatarURL(),
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
},
footer: {
text: `topic requested by: ${message.author.username} ${s}`,
icon_url: '',
},
color: 0x7732a8,
}
interaction.editReply({ embeds: [embed] });
}}
There's no issues in console, I tried to log, still nothing. Just "This interaction failed."
I am currently running the 7 nodes example given in quorum-examples github repo. I have deployed a very simple storage contract which gets and sets the value. As per the example, I am able to interact with the smart contract inside the geth node cmd line. However I would like to interact with it using another address outside the node and so I wrote the following code:
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:22000'))
const { Transaction } = require('#ethereumjs/tx')
const { default: Common } = require('#ethereumjs/common')
const run = async () => {
const contractInstance = await new web3.eth.Contract(
[
{
constant: true,
inputs: [],
name: 'storedData',
outputs: [{ name: '', type: 'uint256' }],
payable: false,
type: 'function',
},
{
constant: false,
inputs: [{ name: 'x', type: 'uint256' }],
name: 'set',
outputs: [],
payable: false,
type: 'function',
},
{
constant: true,
inputs: [],
name: 'get',
outputs: [{ name: 'retVal', type: 'uint256' }],
payable: false,
type: 'function',
},
{
inputs: [{ name: 'initVal', type: 'uint256' }],
payable: false,
type: 'constructor',
},
],
'0xd9d64b7dc034fafdba5dc2902875a67b5d586420'
)
const customCommon = Common.forCustomChain('mainnet', {
chainId: 10,
})
const txCount = await web3.eth.getTransactionCount(
'ed9d02e382b34818e88b88a309c7fe71e65f419d'
)
const txData = {
nonce: web3.utils.toHex(txCount),
gasLimit: '0x47b760',
gasPrice: '0x00',
value: '0x0',
chainId: 10,
to: '0xd9d64b7dc034fafdba5dc2902875a67b5d586420',
data: contractInstance.methods.set(10).encodeABI(),
}
const tx = Transaction.fromTxData(txData, { common: customCommon })
const signedTx = tx.sign(
Buffer.from(
'e6181caaffff94a09d7e332fc8da9884d99902c7874eb74354bdcadf411929f1',
'hex'
)
)
const serializedTx = signedTx.serialize()
const result = await web3.eth.sendSignedTransaction(
`0x${serializedTx.toString('hex')}`
)
return result
}
run().then(console.log).catch(console.log)
However whenever I try to send the transtion, it always errors out to
"Transaction has been reverted by the EVM:\n{\n \"blockHash\": \"0xd6b06321882912185f5e1d3401a012f58b6bbf7eee1e1d2c6c2cd80a0e13bbdc\",\n \"blockNumber\": 5,\n \"contractAddress\": null,\n \"cumulativeGasUsed\": 23751,\n \"from\": \"0x0fbdc686b912d7722dc86510934589e0aaf3b55a\",\n \"gasUsed\": 23751,\n \"logs\": [],\n \"logsBloom\": \"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\n \"status\": false,\n \"to\": \"0x9d13c6d3afe1721beef56b55d303b09e021e27ab\",\n \"transactionHash\": \"0x8c7fd175ab037e24e531804774e8b89bf5aea25de8d99aa9bc2c034229603299\",\n \"transactionIndex\": 0\n}",
Do let me know if more info is required and I will update the post.
The smartcontract code is as follows:
pragma solidity ^0.5.0;
contract simplestorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}
I think i met the similar issue as well. My issue was invalid chain id signer. I checked many docs and tried to set the custom chain id which was what you did about "common". But nothing changed until i changed the version of ethereumjs-tx to ^1.3.7. btw you dont need common if you try my solution.
I'm trying to use the Jodit editor and wish to use the image uploading capabilities to specify a folder and path of where to upload it to using a PHP script.
I'm trying to put in some console.log statements to check my values, but when I select an image, I receive this error in the console which I don't know how to fix.
The code I've used in the page is:
<script>
var editor = new Jodit('#editor_Jodit',{
enableDragAndDropFileToEditor: true,
uploader: {
url: 'connector/upload.php',
format: 'json',
pathVariableName: 'path',
filesVariableName: 'images',
prepareData: function (data) {
return data;
},
isSuccess: function (resp) {
return !resp.error;
},
getMsg: function (resp) {
return resp.msg.join !== undefined ? resp.msg.join(' ') : resp.msg;
},
process: function (resp) {
return {
files: resp[this.options.uploader.filesVariableName] || [],
path: resp.path,
baseurl: resp.baseurl,
error: resp.error,
msg: resp.msg
};
},
error: function (e) {
this.events.fire('errorPopap', [e.getMessage(), 'error', 4000]);
},
defaultHandlerSuccess: function (data, resp) {
var i, field = this.options.uploader.filesVariableName;
if (data[field] && data[field].length) {
for (i = 0; i < data[field].length; i += 1) {
this.selection.insertImage(data.baseurl + data[field][i]);
}
}
},
defaultHandlerError: function (resp) {
this.events.fire('errorPopap', [this.options.uploader.getMsg(resp)]);
}
}
});
editor.value = '<p>start</p>';
</script>
Try to remove the following line:
filesVariableName: 'images'
Replace with a function
filesVariableName: function (r) {
return 'images'
},
I want to implement a functionality that enables users to filter/get businesses by location. This is my logic:
Declare a variable to hold the filtered array
Loop through the businesses
If the query is not undefined
Call the filter method on the businesses
if the query is equal to the location available in the database
Push the businesses with the specified location(s) into the array
return a success message and status code with the businesses in the
specified location or an error message with the appropriate status code.
This is the mock database:
const businesses = [
{
id: 1,
businessName: 'Kulikuli and Sons Limited',
description: 'We take you to heaven and back',
email: 'kososhi#gmail.com',
location: 'Kaduna',
category: 'Hospitality',
phoneNumber: '07033288342'
},
{
id: 2,
businessName: 'Rochas Limited',
description: 'We satisfy all your maintenance',
email: 'rochas2u#gmail',
location: 'Lagos',
category: 'Repairs and Maintenance',
phoneNumber: '07033288341'
},
{
id: 3,
businessName: 'Lekoto Travels',
description: 'Travel with us and you won\'t regret it',
email: 'lekotoboss#gmail.com',
location: 'Kaduna',
category: 'Travels and Tours',
phoneNumber: '07033288344'
},
];
This is the method to control the route: GET /businesses?location=<location>
static filterByLocation(req, res) {
const filteredLocation = [];
for (let i = 0; i < businesses.length; i += 1) {
if (typeof req.query.location !== 'undefined') {
businesses.filter((business) => {
if (business.location === req.query.location) {
filteredLocation.push(business);
}
});
}
return res.status(200).send({
status: 'Success',
location: filteredLocation
});
}
return res.status(404).send({
status: 'Fail',
message: 'Location not found'
});
}
However, the code isn't working as expected. Where am I getting it wrong?
try this, Filter function return filtered result not need to push in array based on condition, and res.send does not return JSON so you have to use res.json() or res.send(JSON.stringify(json)). You are returning response from inside for loop that will not work.
static filterByLocation(req, res) {
const filteredLocation = businesses.filter((business) => {
return business.location === req.query.location;
});
if (filteredLocation.length !== 0)
return res.status(200).json({
status: 'Success',
location: filteredLocation
});
return res.status(404).json({
status: 'Fail',
message: 'Location not found'
});
}
WL.JSONStore.get(collectionName).change(data, options) method does not seem to work for duplicate values. I get duplicate values entered whenever data is loaded through the adapter. Below is the code that I have used to avoid duplicate entries.
init(){
console.log('JSONStore init function callled');
let collections = {
activities: {
searchField: {serialKey: 'string'},
adapter: {
name: 'ServiceAdapter',
add: 'pushActivities',
remove: 'removeActivity',
replace: 'replaceActivity',
load: {
procedure: 'getActivities',
params: [],
key: 'rows'
}
}
}
}
WL.JSONStore.init(collections).then((success) => {
console.log('-->JSONStore init success')
}, (failure) => {
console.log('-->JSONStore init failed', failure)
})
}
load() {
let dataRequest = new
WLResourceRequest("/adapters/ServiceAdapter/getActivities",
WLResourceRequest.GET);
dataRequest.send().then(
(response) => {
this.data = response.responseJSON.rows;
this.activityService.put(this.data);
})
}
put(data){
console.log('--> JSONStore put function called');
let collectionName = 'activities';
let options = {
replaceCriteria: ['serialKey'],
addNew: true,
markDirty: false
};
WL.JSONStore.get(collectionName).change(data, options).then((success) => {
console.log('--> JSONStore put success')
}, (failure) => {
console.log('--> JSONStore put failed', failure)
})
}
Adapter Function:
function getActivities() {
var path = 'employees' + '/_all_docs?include_docs=true';
var input = {
method : 'get',
returnedContentType : 'json',
path : path,
};
var response = MFP.Server.invokeHttp(input);
if (!response.rows) {
response.isSuccessful = false;
return response;
} else {
var results = [];
for (var i=0; i < response.rows.length; i++) {
results.push(response.rows[i].doc);
}
return {'rows': results};
}
}
I have even tried by:
searchFields: {serialKey: 'string',serialId: 'string'}
replaceCriteria: ['serialKey','serialId']
But no luck.
NOTE: There is no error in the former one, whereas the later results in an error.
ERROR : PROVISION_TABLE_SEARCH_FIELDS_MISMATCH (I have already tried to destroy the collection and perform the change, as the link suggests.
I have followed the below link:
https://www.youtube.com/watch?v=Ep6w1zXoI-k
I am using the below versions:
mfpdev : 8.0.0-2017102406
Let me know if you need any more details.