Hello I am working on my mute command and I came up with this error:
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.
at Function.resolve (/app/node_modules/discord.js/src/util/BitField.js:150:19)
at /app/node_modules/discord.js/src/util/BitField.js:148:54
at Array.map (<anonymous>)
at Function.resolve (/app/node_modules/discord.js/src/util/BitField.js:148:40)
at RoleManager.create (/app/node_modules/discord.js/src/managers/RoleManager.js:112:58)
at Client.<anonymous> (/app/index.js:586:41)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
I want to make a mute role for my mute command
here is my command:
message.guild.roles.create({
data: {
name: 'muted',
color: '#ff0000',
permissions: [
"SEND_MESSAGES" === false,
"ADD_REACTIONS" === false
]
},
reason: 'to mute people',
})
.catch(console.error);
} catch (e) {
console.log(e.stack);
}
} return message.channel.send('Cant')
I don't quite know how to fix it please help me
I stumbled onto this old question today, and though I'm quite a bit late, the current primary answer posted by Androz2091 is incorrect.
You can't use an array for the permissions value (it must be an object):
This is completely false. In no version of discord.js from v11 to v13 was the permissions value for creating a role an object literal in the form presented by that answer. The permissions value must be a PermissionResolvable. A PermissionResolvable can be a string such as "SEND_MESSAGES", or it can be an array of such strings. Review the docs.
As for what the OP actually got wrong, notice how they specified their permission strings:
permissions: [
"SEND_MESSAGES" === false,
"ADD_REACTIONS" === false
]
That is incorrect. That's the same thing as doing permissions: [ false, false ]. Obviously false is not a permission, which is why you are getting the invalid bitfield flag error.
That is not how permissions work when creating roles. If you look at your guild's role permissions, you'll see that each permission has two states: enabled or disabled. The way the permissions value works in guild.roles.create() is, it enables any permissions that are specified and disables ALL other permissions. That means, if you want SEND_MESSAGES and ADD_REACTIONS disabled for your Muted role, you simply need to not include them in the permissions array.
Instead, include whatever permissions the muted users are supposed to have. For example, if they should be able to view channels, give them VIEW_CHANNEL. Here is an example solution:
permissions: [
"VIEW_CHANNEL",
"READ_MESSAGE_HISTORY"
]
That should work pretty well for a Muted role. Note that how permissions work in this way is still the same for both discord.js v12 and v13, but the way in which you create roles itself has changed a little bit between the versions. However, this solution should still be applicable to both versions.
You can't use an array for the permissions value (it must be an object):
message.guild.roles.create({
data: {
name: 'muted',
color: '#ff0000',
permissions: {
SEND_MESSAGES: false,
ADD_REACTIONS: false
}
},
reason: 'to mute people',
})
.catch(console.error);
} catch (e) {
console.log(e.stack);
}
} return message.channel.send('Cant')
Reinstalling discord.js worked for me.
npm uninstall discord.js
npm install discord.js
Related
I'm trying to create two users: an admin ide who has all permissions, and a dev user who can only query the /select path and a specific collection collec1.
I used the Rule-Based Authorization Plugin and I have the following security.json file:
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[
{
"name":"read2",
"role":["read2"],
"collection":["collec1"],
"path":["/select"],
"method":["GET"],
"params":{},
"index":1},
{
"name":"all",
"role":"admin",
"index":2}],
"user-role":{
"ide":"admin",
"dev":["read2"],
},
"":{"v":0}}
I made sure to put the more specific permission on top.
When I try to query the collection with dev user, I get an error 403. Any would help would be appreciated.
I am getting 403 errors with sp-rest-proxy. I was originally using the “User Credentials” strategy which allowed me to GET data, but not POST it. So now I’m am trying the “Addin only permissions”. My I.T. team was able get the app registered for me. but I am still receiving the below error now even with GET.
Error Details:
{
"readyState": 4,
"responseText": "{\"error\":{\"code\":\"-2147024891, System.UnauthorizedAccessException\",\"message\":{\"lang\":\"en-US\",\"value\":\"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))\"}}}",
"responseJSON": {
"error": {
"code": "-2147024891, System.UnauthorizedAccessException",
"message": {
"lang": "en-US",
"value": "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
}
}
},
"status": 403,
"statusText": "Forbidden"
}
Things I suspect I messed up on:
I strongly think its my server/private config I have the following…
const RestProxy = require('sp-rest-proxy');
const settings = {
configPath: './config/private.json',
port: 8081,
};
const restProxy = new RestProxy(settings);
restProxy.serve();
and private (not the actual values I am using expect for "strategy" )
{
"siteUrl": "https://ORGANIZTION.sharepoint.com",
"strategy": "OnlineAddinOnly",
"clientId": "0000000-000000-000000-0000-00000000",
"clientSecret": "000000000000000000000000000000",
"realm": "00000-0000-0000-0000-000000"
}
I couldn’t find much on the “strategy” value on the sp-rest-proxy or the node-sp-auth side of the documentation. I can assume its OnlineAddinOnly but I’m not able to find the specific syntax for what possible values this attribute expects. I also noticed that the “clientSecret” is changing once I run the server, I assume this is an intentional encryption.
During the App registration phase (step 5 of this https://github.com/s-KaiNet/node-sp-auth/wiki/SharePoint%20Online%20addin%20only%20authentication) I had the IT folk set the “right” attribute in AppPermissionRequests to “Write” instead “FullControl”, I noticed that “FullControl” seems to be used in most example though I wasn’t sure if it was required. Can anyone confirm that?
[Edit: confirmed this is not the issue by setting this to FullControl]
Intention:
I am trying to build an internal data management tool that only needs to work on localhost to get manipulate and replace json files in my teams SharePoint. (just in a nice way so that non-coders can do this). The “sp-rest-proxy” library seems to be what I need to implement the REST API effectively in react.
As far as I know, SharePoint app-only access is disabled by default. You need to ask your administrator to enable it by running the following command:
set-spotenant -DisableCustomAppAuthentication $false
The answer likely in the XML AppPermissionRequests. The creator of the library was able to point me to a better example and I had noticed some differences we had a different scope value and no AllowAppOnlyPolicy adding these seems to have fixed most of the issue. I am able to confirm that I can now do GET.
I am still having issues with GetFolderByServerRelativeUrl and using the to add/replace files but I am not sure that is related and will treat it as a separate issue as it may not be related to sp-rest-proxy or node-sp-auth
the correct AppPermissionRequests XML should be this ->
and as #Michael Han_MSFT mentioned you should ensure that DisableCustomAppAuthentication is set to false
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
</AppPermissionRequests>
I'm new to coding javascript and I'm coding discord.js. I've been trying to add an auto role feature so that when someone joins the discord server they automatically obtain the default role. However, I've been struggling as all the tutorials or other code explaining it is usually out-dated. So when I try and run the bot I get this error message.
TypeError: fn.bind is not a function
at Map.find (C:\Users\stuar\Desktop\Discord Bot\node modulesN^discordjs\collection\dist\index.js:158:21) at Client.<anonymous> (C:\Users\stuar\Desktop\Discord Bot\index.js:71:41)
at Client.emit (events.js:327:22)
at Object.module.exports [as GUILD_MEMBER_ADD] (C:\Users\stuar\Desktop\Discord Bot\node modules\discord.js\src\client\websocket\handlers\GUILD MEMBER ADD.js:16:14)
at WebSocketManager. handlePacket (C : \Users\stuar\Desktop\Discord Bot \node_modules\discordjs\src\client \websocket \WebSocketManager. j s : 386:31 )
at WebSocketShard.onPacket (C:\Users\stuar\Desktop\Discord Bot\node modules\discord.j s\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\stuar\Desktop\Discord Bot\node modules\discord.js\src\client\websocket\WebSocketShard.js: 293:10)
at WebSocket.onMessage (C:\Users\stuar\Desktop\Discord Bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:29)
at Receiver.receiverOnMessage (C:\Users\stuar\Desktop\Discord Bot\node_modules\ws\lib\websocket.js: 800:20)
And this is my code that it seems to not like:
// Auto Role
client.on('guildMemberAdd", member => {
console.log("User " + member.user.tag + " has joined the server!");
var role = member.guild.roles.cache.find("name", "User");
member.addRole(role);
});
You're using an old version of Collection.find(): in its current version the "property-value" way of using .find is no longer supported, you need to provide a function. You can find the docs here.
Here's how you can code it:
client.on('guildMemberAdd', member => {
let role = member.guild.roles.cache.find(r => r.name == 'User')
member.roles.add(role)
})
Also, as you may have noticed, you also need to write member.roles.add, since GuildMember.addRole() is a method from v11.
I've inherited a simple site with staging and production projects living on Google App Engine. Yesterday made a simple deploy to staging (using CircleCI), the first deploy since January. Since then the site won't load and the logs show an exception we haven't had before:
"Cannot read property 'parsePath' of undefined" when trying to go to the home page at: /
Our code does not make any call to 'parsePath', so it must be some underlying machinery.
I reverted the code change and re-pushed the staging branch with the code that's been live since January (and is live and error-free right now in production), deploy was successful, but the same symptom is there still in staging! (Needless to say, we can't deploy anything to production until we know what the heck is going on)
I've been looking through the circleCI deploy logs for clues- one difference is during the "gcloud auth activate-service-account" step, it wasn't able to update the compute/zone property (but the build still succeeded):
Updated property [core/project].
WARNING: You do not appear to have access to project [veryloudstatic] or it does not exist.
Updated property [compute/zone].
What should I be looking at on the GAE side? Has anyone seen this exception before, or know enough about how GAE works to suggest places to troubleshoot? We haven't made any changes to these GAE projects in the past few months, so I'm wondering if some internal updates could be the issue?
Cannot read property 'parsePath' of undefined
Expand all | Collapse all {
insertId: "owonpfihz4box5kp7"
labels: {
appengine.googleapis.com/instance_name: "aef-default-20190620t195308-lsn2"
compute.googleapis.com/resource_id: "2700574583511472701"
compute.googleapis.com/resource_name: "b6282fd5dc84"
compute.googleapis.com/zone: "us-central1-f"
}
logName: "projects/veryloudstatic/logs/appengine.googleapis.com%2Fstderr"
receiveTimestamp: "2019-06-21T13:53:47.746443513Z"
resource: {
labels: {
module_id: "default"
project_id: "veryloudstatic"
version_id: "20190620t195308"
}
type: "gae_app"
}
textPayload: "Cannot read property 'parsePath' of undefined
"
timestamp: "2019-06-21T13:53:45Z"
}
35.233.167.246 - "GET /" 500 148 "-" "GoogleStackdriverMonitoring-UptimeChecks(https://cloud.google.com/monitoring)"
Expand all | Collapse all {
httpRequest: {
latency: "0.166s"
referer: "-"
remoteIp: "35.233.167.246"
requestMethod: "GET"
requestUrl: "/"
responseSize: "148"
status: 500
userAgent: "GoogleStackdriverMonitoring-UptimeChecks(https://cloud.google.com/monitoring)"
}
insertId: "28alo0fexgmee"
jsonPayload: {…}
labels: {…}
logName: "projects/veryloudstatic/logs/appengine.googleapis.com%2Fnginx.request"
receiveTimestamp: "2019-06-21T13:53:47.746443513Z"
resource: {…}
timestamp: "2019-06-21T13:53:45.536Z"
trace: "projects/veryloudstatic/traces/5190f7942330e15370ff65d1c79c5963"
}
Without more of a stack trace its hard to tell, but check your dependency versions if there are any. An underlying dependency may have updated. Make sure to check both your app code and the CircleCI base image.
I want to modify my code structure using eslint of airbnb. I have follwed these instruction given in eslint-config-airbnb. After initiating the command
npm run lint, results consists of 'fetch' is not defined and also, 'localStorage' is not defined.
I have gone through this github issue, but still error is shown as the same 'fetch is not defined'. Is there any solutions for it.
No need to add it as an exception, just add this to your .eslintrc and eslint will know what it is:
"env": {
"browser": true
}
You can configure your .eslintrc file with globals.
Add this to your .eslintrc file.
"globals": {
"localStorage": true,
"fetch": true
}
you can try to access to the fetch and localStorage through window object.
window.fetch, window.localStorage