pan andrzej
pan andrzej
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by pan andrzej on 6/19/2023 in #djs-questions
Editing a button issue
So im basically trying to make a slash command that edits one of 2 buttons in Embed Message. And after invoking command, it throws this error: components[0].components[BASE_TYPE_BAD_LENGTH]: Must be between 1 and 1521 in length. at message.edit() How I can do that in a correct way? Is that even possible? Here's my code:
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("button")
.setDescription("block or unblock")
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addBooleanOption((option) =>
option
.setName("state")
.setDescription("Block or unblock")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("button")
.setDescription("which one?")
.setRequired(true)
),

async execute(interaction) {
const { options, channel } = interaction;
const buttonState = options.getBoolean("state");
const buttonName = options.getString("button");

let buttonIndex;

if (buttonName.toLowerCase() === "first") {
buttonIndex = 1;
} else if (buttonName.toLowerCase() === "second") {
buttonIndex = 0;
} else {
return interaction.reply({
content: "Incorrect name!",
ephemeral: true,
});
}

const message = await channel.messages.fetch("1120412253901045832");

if (!message) {
return interaction.reply({
content: "No messages!",
ephemeral: true,
});
}

const buttons = message.components[0].components;
const buttonToEdit = buttons[buttonIndex];

buttonToEdit.disabled = buttonState;
buttonToEdit.style = buttonState ? "SUCCESS" : "DANGER";

await message.edit({ components: [buttons] });

interaction.reply({
content: "Button updated!",
ephemeral: true,
});
},
};
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("button")
.setDescription("block or unblock")
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addBooleanOption((option) =>
option
.setName("state")
.setDescription("Block or unblock")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("button")
.setDescription("which one?")
.setRequired(true)
),

async execute(interaction) {
const { options, channel } = interaction;
const buttonState = options.getBoolean("state");
const buttonName = options.getString("button");

let buttonIndex;

if (buttonName.toLowerCase() === "first") {
buttonIndex = 1;
} else if (buttonName.toLowerCase() === "second") {
buttonIndex = 0;
} else {
return interaction.reply({
content: "Incorrect name!",
ephemeral: true,
});
}

const message = await channel.messages.fetch("1120412253901045832");

if (!message) {
return interaction.reply({
content: "No messages!",
ephemeral: true,
});
}

const buttons = message.components[0].components;
const buttonToEdit = buttons[buttonIndex];

buttonToEdit.disabled = buttonState;
buttonToEdit.style = buttonState ? "SUCCESS" : "DANGER";

await message.edit({ components: [buttons] });

interaction.reply({
content: "Button updated!",
ephemeral: true,
});
},
};
6 replies
CC#
Created by pan andrzej on 5/8/2023 in #help
❔ Realm .NET Error
I need help with Realm .NET. I'm making a plugin for unity game and I have server hosted on linux and I'm making a plugin on windows 10. Here's sample of my code:
public async Task MongoDBConnect()
{
var app = App.Create("my-realm");

var user = await app.LogInAsync(Credentials.Anonymous());

var mongoClient = user.GetMongoClient("mongodb://user:password@ip:port/&authSource=admin&connectTimeoutMS=1000&socketTimeoutMS=1000&serverSelectionTimeoutMS=1000");
var database = mongoClient.GetDatabase("db");
collection = (IMongoCollection<PlayerModel>)database.GetCollection<PlayerModel>("playerdatas");
}
public async Task MongoDBConnect()
{
var app = App.Create("my-realm");

var user = await app.LogInAsync(Credentials.Anonymous());

var mongoClient = user.GetMongoClient("mongodb://user:password@ip:port/&authSource=admin&connectTimeoutMS=1000&socketTimeoutMS=1000&serverSelectionTimeoutMS=1000");
var database = mongoClient.GetDatabase("db");
collection = (IMongoCollection<PlayerModel>)database.GetCollection<PlayerModel>("playerdatas");
}
And this code (excatly App.Create) is throwing this error:
System.TypeInitializationException: The type initializer for 'Realms.Sync.AppHandle' threw an exception. ---> System.DllNotFoundException: realm-wrappers
at (wrapper managed-to-native) Realms.SynchronizationContextScheduler.install_scheduler_callbacks(Realms.SynchronizationContextScheduler/get_context,Realms.SynchronizationContextScheduler/post_on_context,Realms.SynchronizationContextScheduler/release_context,Realms.SynchronizationContextScheduler/is_on_context)
--- End of inner exception stack trace ---
System.TypeInitializationException: The type initializer for 'Realms.Sync.AppHandle' threw an exception. ---> System.DllNotFoundException: realm-wrappers
at (wrapper managed-to-native) Realms.SynchronizationContextScheduler.install_scheduler_callbacks(Realms.SynchronizationContextScheduler/get_context,Realms.SynchronizationContextScheduler/post_on_context,Realms.SynchronizationContextScheduler/release_context,Realms.SynchronizationContextScheduler/is_on_context)
--- End of inner exception stack trace ---
and actually error says about missing realm-wrappers.dll, and problem is that it's generating only files for windows (x64 and x86). What I can do in that situation?
2 replies
CC#
Created by pan andrzej on 5/1/2023 in #help
❔ MongoDB.Driver.MongoConnectionException:
Hi, I have problem with finding document in MongoDB collection. Whenever method collection.find is fired, it throws this error: MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.MissingMethodException: void System.Security.Cryptography.Rfc2898DeriveBytes..ctor(string,byte[],int,System.Security.Cryptography.HashAlgorithmName) here's code:
var client = new MongoClient("here's my uri");
var database = client.GetDatabase("test");
var collection = database.GetCollection<PlayerModel>("playerdatas");

var playerFilter = Builders<PlayerModel>.Filter.Eq("SteamID", player.UserId);
//this line throws error
var playerData = collection.Find(playerFilter).FirstOrDefault();
var client = new MongoClient("here's my uri");
var database = client.GetDatabase("test");
var collection = database.GetCollection<PlayerModel>("playerdatas");

var playerFilter = Builders<PlayerModel>.Filter.Eq("SteamID", player.UserId);
//this line throws error
var playerData = collection.Find(playerFilter).FirstOrDefault();
I'm using .NET framework 4.8.1, mongoDB 2.19.1 and Scram-SHA-1. Anyone know why it's happening?
8 replies