discord.js v14 create channel - discord.js

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.

Related

DyDx Portocol Typescript Clinet: TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object

I am getting error when DyDx Client call is being made:
client.private.createOrder(
{
market: props.market,
side: orderSide === "BUY" ? OrderSide.BUY : OrderSide.SELL,
type: OrderType.LIMIT,
timeInForce: TimeInForce.GTT,
postOnly: postOnly === "FALSE" ? false : true,
size: '0.1',
price: '1',
limitFee: '0.015',
expiration: '2023-01-30T21:30:20.200Z',
clientId: "dasdasdasdasdasda"
},
'1', // required for creating the order signature
).then((createOrderResponse) => {
console.log("Got Response from create order action")
console.log(createOrderResponse)
}).catch((errorFromCreateOrder) => {
console.log(errorFromCreateOrder)
})
I am not sure what is wrong here, I try to print the details of the object and all the data is available.
Here is the object, I am passing:
{
"market": "ETH-USD",
"side": "BUY",
"type": "LIMIT",
"timeInForce": "GTT",
"postOnly": false,
"size": "0.1",
"price": "1",
"limitFee": "0.015",
"expiration": "2023-01-30T21:30:20.200Z",
"clientId": "CL1674386882222"
}
Here is the full error:
DyDxOrderComponent.tsx:121 TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
at fromObject (index.js:311:1)
at from (index.js:137:1)
at push../node_modules/node-libs-browser/node_modules/buffer/index.js.Buffer.from (index.js:149:1)
at Private.sign (private.ts:1080:1)
at Private.request (private.ts:125:1)
at Private.post (private.ts:154:1)
at Private.createOrder (private.ts:510:1)
Let me know if you need any more information.

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

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" ]
}

discord.js TypeError Cannot Read properties of undefined (reading 'options')

I created a ban command for my discord bot, but I encountered such an error
code :
module.exports = {
name: "ban",
permission: "BAN_MEMBERS",
options: [
{
name: "target",
description: "banlamak için bir hedef seçin.",
type: "USER",
required: true,
},
{
name: "reason",
description: "banlamak için bir sebep seçin.",
type: "STRING",
required: true,
},
{
name: "messages",
description: "Seçeneklerden birini seç.",
type: "STRING",
required: true,
choices: [
{
name: "hiç birini silme",
value: 0
},
{
name: "önceki 7 gün",
value: 7
}
]
},
],
execute(client, interaction) {
const Target = interaction.options.getMember('target');
if (Target.id === interaction.member.id)
return interaction.followUp({embeds: [new MessageEmbed().setColor('BLACK').setDescription(`⛔ kendini yasaklayamazsın. `)]})
if (Target.permissions.has('ADMINISTRATOR'))
return interaction.followUp({embeds: [new MessageEmbed().setColor('BLACK').setDescription(`⛔ Bir Yöneticiyi Yasaklayamazsınız. `)]})
const Reason = interaction.options.getString('reason');
if (Reason.length > 512)
return interaction.followUp({embeds: [new MessageEmbed().setColor('BLACK').setDescription(`⛔ sebep 512 karakteri geçemez. `)]})
const Amount = interaction.options.getString('messages');
Target.ban({ days : Amount, reason : Reason})
interaction.followUp({embeds : [new MessageEmbed().setColor("WHITE").setDescription(`✅ **${Target.user.username}** banlanmıştır. `)]})
}
}
if the error occurs on the first line where this is executed
const Target = interaction.options.getMember('target');
then the issue could be caused by options not being a member of the interaction. Are you sure that the interaction you are running is a command interaction. You could check this easily by adding this call before anything else. If nothing is ran after this is executed then it means the interaction you are interacting with is not a command so options won't exist on that interaction.
if (!interaction.isCommand()) return;

Mongoose instance .save() not working when embedded array object changed

I am using Mongoose npm module to manage mongodb.
This is schema of mongodb collection what I am going to update.
var UserSchema = new Schema({
username: {
type: String,
unique: true,
required: true
},
email: {
type: String,
unique: true,
required: true
},
cards: []
});
module.exports = mongoose.model('User', UserSchema);
inside post request, here req is request object of post request.
and res is response object.
User.findById(userID).exec(function (err, doc) {
let cardInfo = req.cardInfo
let cardIndex = req.cardIndex
doc["cards"][0] = cardInfo;
console.log(doc)
/* here I got right doc object as I requested
{
"_id": "59f3bdd488f912234fcf06ab",
"email": "test#gmail.com",
"username": "test",
"__v": 2,
"cards": [
{
"testNo": "42424242424242"
}
]
}
*/
doc.save(function (err) {
if (err) {
return res.json({
success: false,
msg: 'Card add error'
});
}
res.json({
success: true,
msg: 'Successful updated card.'
});
});
})
I got message 'Successful updated card.', but actually, It doesn't save.
How to solve it. Thanks.
The problem is that mongoose don't knwo your array is modified.
You can use 2 solutions :
markModified
This function will mark the embedded element as modified and force a resave of it.
It will tell mongoose to resave this element.
User.findById(userID).exec(function (err, doc) {
let cardInfo = req.cardInfo
let cardIndex = req.cardIndex
doc["cards"][0] = cardInfo;
console.log(doc)
/* here I got right doc object as I requested
{
"_id": "59f3bdd488f912234fcf06ab",
"email": "test#gmail.com",
"username": "test",
"__v": 2,
"cards": [
{
"testNo": "42424242424242"
}
]
}
*/
doc.markModified('cards');
doc.save(function (err) {
if (err) {
return res.json({
success: false,
msg: 'Card add error'
});
}
res.json({
success: true,
msg: 'Successful updated card.'
});
});
})
Use a full schema.
To avoid the markModified trick, you should describe the content of cards in your schema. This way mongoose will be able to determine if it needs to save the field or not.
Here is the way to declare your schema properly :
const CardSchema = new Schema({
testNo: String,
});
var UserSchema = new Schema({
username: {
type: String,
unique: true,
required: true
},
email: {
type: String,
unique: true,
required: true
},
cards: [CardSchema]
});
module.exports = mongoose.model('User', UserSchema);
This way, mongoose will be able to detect if a value inside cards changed and save only the modified item.
If you can do it (static schema), this is clearly the good way to do it.
If you just want to update cards based on cardIndex:
User.update({_id: userID}, {'$set': {
'cards.cardIndex': cardInfo
}}, function(err) {
//code
}
Thanks for all answers.
I find this solution in addition.
doc["cards"].set(cardIndex, cardInfo)
Cheers!

Kendo UI scheduler create

Im having problems with the kendo scheduler. Im using it together with AngularJS.
When i create an event and click save, first of the create window wont close and when i manually close it the event is not there. But if i reload the page the event is shown there, so it is getting saved to the database.
Scheduler dataSource:
var dataSource = {
transport: {
read: read,
create: create,
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
},
},
schema: {
model: {
id: "occurrenceId",
fields: {
occurrenceId: { from: "occurrenceId", type: "number" },
title: { from: "title", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "start" },
end: { type: "date", from: "end" },
description: { from: "description" },
recurrenceId: { from: "RecurrenceID" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
isAllDay: { type: "boolean", from: "IsAllDay" }
}
}
}
};
And here is the create function:
function create(data) {
var occurrence = {
"title": data.data.title,
"start": data.data.start,
"end": data.data.end,
"description": data.data.description,
"recurrenceId": data.data.recurrenceId,
"recurrenceRule": data.data.recurrenceRule,
"recurrenceException": data.data.recurrenceException,
"isAllDay": data.data.isAllDay,
"ownerId": $scope.resource.id
}
$http({
method: 'POST',
url: '/api/occurrences',
data: JSON.stringify(occurrence),
contentType: "application/json"
}).success(function (response) {
response.data
});
}
Try returning the inserted data (including the generated ID) from your create function. On your http post's success, it doesn't seem to be doing anything meaningful.
From Kendo-UI data source API reference: The remote service must return the inserted data items and the data item field configured as the id must be set. For example if the id of the data item is ProductID the "create" server response must be [{ "ProductID": 79 }].

Resources