aa battery
aa battery
Explore posts from servers
CC#
Created by aa battery on 11/2/2023 in #help
❔ Just got started with leetcode after a year of learning, I need some help...
So the title says it all I guess, I started with leetcode after around a year with learning and I started away with one of its problems. It took me two hours to finally get it right but my code felt so redundant and long for such a simple problem. Can I get some feedback on how to make it more efficient? Thanks So here is what I had after I was done (it was the two sum problem)
public class Solution {
public int[] TwoSum(int[] nums, int target) {
for(int i = 0; i <= nums.Length; i++) {
int e = i < nums.Length ? i + 1 : i;
var excludedNums= new int[nums.Length-e];
Array.Copy(nums, e, excludedNums, 0, excludedNums.Length);

foreach(int a in excludedNums) {
int test = nums[i] + a;
if (test == target) {
if (a == nums[i]) {
return new int[] { i, Array.IndexOf(nums, a, i+1) };
}
return new int[] { i, Array.IndexOf(nums, a) };
};
}
}
return new int[2];
}
}
public class Solution {
public int[] TwoSum(int[] nums, int target) {
for(int i = 0; i <= nums.Length; i++) {
int e = i < nums.Length ? i + 1 : i;
var excludedNums= new int[nums.Length-e];
Array.Copy(nums, e, excludedNums, 0, excludedNums.Length);

foreach(int a in excludedNums) {
int test = nums[i] + a;
if (test == target) {
if (a == nums[i]) {
return new int[] { i, Array.IndexOf(nums, a, i+1) };
}
return new int[] { i, Array.IndexOf(nums, a) };
};
}
}
return new int[2];
}
}
25 replies
DIAdiscord.js - Imagine an app
Created by aa battery on 9/16/2023 in #djs-questions
Cannot edit interaction after modal input
Ok so here is my problem, I want to achieve something like so: Step 1: send interaction with button Step 2: user clicks button Step 3: modal shows and user enters stuff Step 4: after submit edit the original interaction Problem is, editReply() and updateMessage() doesn't let me do that (replying to the modal works) and discord api returns with a "Unknown Webhook" error:
DiscordAPIError[10015]: Unknown Webhook
// i cut this part off to save word count
at async Client.<anonymous> (C:\Users\mt\Visual Studio Code\testBot\handler.js:93:17) {
requestBody: {
files: undefined,
json: { content: '', embeds: [Array], components: [Array] }
},
rawError: { message: 'Unknown Webhook', code: 10015 },
code: 10015,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/webhooks/bleh/bleh/messages/@original'
}
DiscordAPIError[10015]: Unknown Webhook
// i cut this part off to save word count
at async Client.<anonymous> (C:\Users\mt\Visual Studio Code\testBot\handler.js:93:17) {
requestBody: {
files: undefined,
json: { content: '', embeds: [Array], components: [Array] }
},
rawError: { message: 'Unknown Webhook', code: 10015 },
code: 10015,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/webhooks/bleh/bleh/messages/@original'
}
Is there a way to achieve step 4 as defined?
52 replies
DIAdiscord.js - Imagine an app
Created by aa battery on 9/14/2023 in #djs-questions
Unable to use updateMessage() on a message that has already used updateMessage()
So I have this modal that when it is submitted, it modifies the message that had the button to show the modal to say "Loading..." while I have some stuff running, but then if I want to use updateMessage() on that message it wont work and would give me this:
DiscordAPIError[40060]: Interaction has already been acknowledged.
at handleErrors (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async InteractionsAPI.reply (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\core\dist\index.js:1602:5)
at async Object.runModal (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\commands\login.js:62:17)
at async Client.<anonymous> (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\handler.js:93:17) {
requestBody: { files: undefined, json: { type: 4, data: [Object] } },
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/ blah blah blah
}
DiscordAPIError[40060]: Interaction has already been acknowledged.
at handleErrors (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async InteractionsAPI.reply (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\node_modules\@discordjs\core\dist\index.js:1602:5)
at async Object.runModal (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\commands\login.js:62:17)
at async Client.<anonymous> (C:\Users\mt\Documents\me stuff\prog\Visual Studio Code\genshinBot\handler.js:93:17) {
requestBody: { files: undefined, json: { type: 4, data: [Object] } },
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/ blah blah blah
}
8 replies
DIAdiscord.js - Imagine an app
Created by aa battery on 9/14/2023 in #djs-questions
Error running a select menu inside a modal (not sure if that's really the issue)
I have this action row with a text box and a select menu which i put inside a modal that is activated with a button:
static cookieField = new ActionRowBuilder(
{
components: [
new TextInputBuilder({
custom_id: "cookieField",
label: "Hoyolab cookie string",
style: TextInputStyle.Short,
placeholder: "_MHYUUID=c19fda-29...",
required: true
}),
new StringSelectMenuBuilder({
custom_id: "serverPicker",
max_values: 1,
options: [
new StringSelectMenuOptionBuilder({
label: "American server", value: "1", emoji: { name: "🇺🇸" }
}),
new StringSelectMenuOptionBuilder({
label: "Europian server", value: "2", emoji: { name: "🇪🇺" }
}),
new StringSelectMenuOptionBuilder({
label: "Asian server", value: "3", emoji: { name: "🏳️" }
}),
new StringSelectMenuOptionBuilder({
label: "HW/TW/MO server", value: "4", emoji: { name: "👎"}
})
]
})
]
}
);
static cookieField = new ActionRowBuilder(
{
components: [
new TextInputBuilder({
custom_id: "cookieField",
label: "Hoyolab cookie string",
style: TextInputStyle.Short,
placeholder: "_MHYUUID=c19fda-29...",
required: true
}),
new StringSelectMenuBuilder({
custom_id: "serverPicker",
max_values: 1,
options: [
new StringSelectMenuOptionBuilder({
label: "American server", value: "1", emoji: { name: "🇺🇸" }
}),
new StringSelectMenuOptionBuilder({
label: "Europian server", value: "2", emoji: { name: "🇪🇺" }
}),
new StringSelectMenuOptionBuilder({
label: "Asian server", value: "3", emoji: { name: "🏳️" }
}),
new StringSelectMenuOptionBuilder({
label: "HW/TW/MO server", value: "4", emoji: { name: "👎"}
})
]
})
]
}
);
5 replies