Discord.js : "Supplied parameter is not a User nor a Role" while creating channel through button interaction - discord.js

The bot was working fine while making this. The error started popping from last week.
I don't understand what's wrong as I have also tried the same code on another bot and it creates channel fine.
I thought maybe it had to do with discord making the 19 character snowflake but that's not the case.
Here is the index.js file (I have a omitted few things)
ID is the member username who clicked the button.
staff1, staff2, everyone roles are defined above. [ const staff1 = "role-id"; etc ]
verifyParent is the ID of the category under which the channel is created. [ Defined above ]
switch (customId) {
case 'VERIFY':
await interaction.guild.channels.create(`${customId + "-" + ID}`, {
type: "GUILD_TEXT",
parent: verifyParent,
permissionOverwrites: [
{
id: interaction.member.id,
allow: [ "SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY" ]
},
{
id: staff1,
allow: [ "SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY" ]
},
{
id: staff2,
allow: [ "SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY" ]
},
{
id: everyone,
deny: [ "SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY" ]
}
]
})
.then(async(channel) => {
channel.send(`${ID} Please send the details.`);
})
.catch(console.log);
}
The error I got:
TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
at PermissionOverwrites.resolve (/home/runner/cum-bot/node_modules/discord.js/src/structures/PermissionOverwrites.js:184:28)
at /home/runner/cum-bot/node_modules/discord.js/src/managers/GuildChannelManager.js:145:81
at Array.map (<anonymous>)
at GuildChannelManager.create (/home/runner/cum-bot/node_modules/discord.js/src/managers/GuildChannelManager.js:145:51)
at Client.<anonymous> (/home/runner/cum-bot/index.js:120:48)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[Symbol(code)]: 'INVALID_TYPE'
}
I have looked at other posts and nothing works. I have tried to reset the bot token and still the same thing.
The same code is working fine on a test bot of mine but not with this one.
And no, the bot is not rate limited.
Thanks!

I believe interaction.member.id is the person who sent the interaction itself. if you are trying to get the person that pressed the button, i believe it is:
{
id: interaction.user.id,
allow: [ "SEND_MESSAGES", "VIEW_CHANNEL", "READ_MESSAGE_HISTORY" ]
}

Related

Sync incompatible role error message in MongoDB App Services even though sync seems to work

I have a Flexible Sync app in MongoDB App Services (formerly MongoDB Realm).
The main model object is an Activity, which should be readable and writable by its owner, but also read-only by a supervisor.
These are the sync roles I have set up:
{
"rules": {
"Activity": [
{
"name": "owner_supervisor_activity_permission",
"applyWhen": {},
"read": {
"$or": [
{
"ownerID": "%%user.id"
},
{
"supervisorID": "%%user.id"
}
]
},
"write": {
"ownerID": "%%user.id"
}
}
]
},
"defaultRoles": [
{
"name": "owner-read-write",
"applyWhen": {},
"read": {
"ownerID": "%%user.id"
},
"write": {
"ownerID": "%%user.id"
}
}
]
}
Although sync seems to work just fine, I get the following error message in the logs for both roles:
Using sync incompatible role "owner_supervisor_activity_permission" for table "Activity". this role will default to deny all access. consider changing this role to be sync compatible (ProtocolErrorCode=201)
I do not know what to do here and I’m wondering if it could be a bug.
Do I need to set the per-collection rules? I thought sync roles overrode those.
Is it a matter of using the applyWhen field?
Thanks

discord.js v14 create channel

I try to create a channel but i always have an error.
I don't find how to fix it.
Don't pay attention to the "req[0]." in "code" it comes from the database, no link with the problem because it works in v13
"It looks like your post is mostly code; please add some more details." I don't know what can I have for more details. haha.
Sorry, English is not my native langage.
error :
throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required
at SequentialHandler.runRequest (/root/project/node_modules/#discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:293:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (/root/project/node_modules/#discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:99:14)
at async REST.request (/root/project/node_modules/#discordjs/rest/dist/lib/REST.cjs:52:22)
at async GuildChannelManager.create (/root/new ascension/node_modules/discord.js/src/managers/GuildChannelManager.js:145:18) {
rawError: {
code: 50035,
errors: {
name: {
_errors: [
{
code: 'BASE_TYPE_REQUIRED',
message: 'This field is required'
}
]
}
},
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/guilds/873350117124628552/channels',
requestBody: {
files: undefined,
json: {
name: undefined,
topic: undefined,
type: undefined,
nsfw: undefined,
bitrate: undefined,
user_limit: undefined,
parent_id: undefined,
position: undefined,
permission_overwrites: undefined,
rate_limit_per_user: undefined,
rtc_region: undefined,
video_quality_mode: undefined
}
}
}
Node.js v18.3.0
code :
action.guild.channels.create(`hello`, {
type: "GUILD_TEXT",
parent: cat[0].ID,
permissionOverwrites: [
{
id: bot.user.id,
allow: ['VIEW_CHANNEL', "MANAGE_CHANNELS"]
},
{
id: action.user.id,
allow: ["VIEW_CHANNEL"]
},
{
id: req[0].ID,
deny: ["VIEW_CHANNEL"]
},
{
id: staff[0].ID,
allow: ["VIEW_CHANNEL"]
}
]
})
You can't set the type of the channel using a string anymore, you have to use the new ChannelType enum. You can import it from the discord.js library, and once you've done that, creating a channel would look something like this:
guild.channels.create({
name: "hello",
type: ChannelType.GuildText,
parent: cat[0].ID,
// your permission overwrites or other options here
});
Also make sure that all of your arguments are being passed in only one object, and the name isn't a separate argument.

Hiding channel with Djs12

I need to lock a text channel, so #everyone cannot see that, but message.author can. I have this code, but everyone can see the channel (and in the channel properties everyone hasn't got permission for send messages or send TTS messages, but above that everything is [/])
message.guild.channels.create(desc, {
type: 'text',
permissionOverwrites: [
{
id: message.guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL'],
},
],
})
The PermissionOverwrites typedef requires a Snowflake (in this case, a role or user ID). However, RoleManager.everyone returns a Role. There are two ways to solve this issue:
Simply just use the id property of the role
{
id: message.guild.roles.everyone.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
Use message.guild.id. Fun fact, the #everyone role shares the same ID as the guild it's in
{
id: message.guild.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},

Discord.js disable #evereyone access to new channel

I need the below code to make channels on command and allow the member role to have access to it while the #everyone role not have access to it.
module.exports = {
name: 'channel',
description: 'Creates a new channel for the user.',
aliases: ['channel'],
cooldown: 5,
execute(message) {
const userName = message.author.username;
const channelName = `Channel for ${userName}`;
message.guild.channels.create(channelName,{
type: 'text',
persmissionOverwrites: [
{
id: message.guild.id,
deny: ['VIEW_CHANNEL'],
deny: ['SEND_MESSAGE'],
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL'],
},
],
});
message.channel.send(`Hi ${message.author} your new channel is ${channelName}`);
},
};
I'm aware that this is bare code but I've been struggling to find a way to have the bot find my member role and apply the deny to any role even if I were to specify the ID in the ID field.
The main reason you are not getting any errors or permissionOverwrites is because you wrote persmissionOverwrites instead of permissionOverwrites
message.guild.id does not return a Role or User.
You need to replace message.guild.id in the first permission overwrite with message.guild.roles.everyone
You made a typo with one of your permissions SEND_MESSAGE which needs to be SEND_MESSAGES
Also, you don't need to add deny twice, it's an array, you can input as many permissions as you want.
So instead of
deny: ['VIEW_CHANNEL'],
deny: ['SEND_MESSAGES'],
Write deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],

dynamically add suggestion chips on Api.ai for Actions on google

I want to add suggestions for the user in my Google Assistant Bot. I am using API.ai for bot development and using fulfilment, I am communicating with my backend for data.
I am not able to send suggestions using suggestions chips to my bot.
I have followed as answered here Webhook response with "suggestion chips"
as well as the document at https://developers.google.com/actions/assistant/responses#json.
But still, I only see simple text response at my bot on device as well as on simulator.
I also checked at https://discuss.api.ai/t/google-assistant-rich-message-responses/5134/19. But didn't find any way to switch to V1 or V2. The sample format also didn't work!
Here are my 2 JSONs:
at API.ai
"fulfillment": {
"speech": "want to proceed further?",
"messages": [
{
"type": 0,
"speech": "want to proceed further?"
}
],
"data": {
"google": {
"conversationToken": "[\"AS-PER-JSON-FROM-SIMULATOR\"]",
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "want to proceed further?",
"displayText": "want to proceed further?"
}
}
],
"suggestions": [
{
"title": "Yes"
},
{
"title": "No"
}
]
}
}
}
]
}
}
},
at action on Google
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "want to proceed?"
}
}
]
},
"noMatchPrompts": [],
"noInputPrompts": []
},
"possibleIntents": [
{
"intent": "assistant.intent.action.TEXT"
}
],
"speechBiasingHints": [
"$subject",
"$answer"
]
}
]
python server
return = '{"speech":"want to proceed?", "data": {"google":{"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"want to proceed?","displayText":"want to proceed?"}}],"suggestions":[{"title":"Yes"},{"title":"No"}]}}}]}}}'
Your JSON is wrong, remove the quotation mark before the data object:
"data" : { ... }
instead of
"data" : "{ ... }"
So basically, you're sending a string containing the object instead of a JSON object.
Solved using format as explained here https://developers.google.com/actions/apiai/webhook
Add 'expectUserResponse' into data -> google
'expectUserResponse': true,
'isSsml': false,

Resources