#How do you create selection menus and buttons in discord deno?
1 messages · Page 1 of 1 (latest)
Could you show me a code example using them?
import { ButtonComponent, MessageComponentTypes } from "@discordeno/types" // or "@discordeno/bot" or "discordeno" based on what you are using
const button: ButtonComponent = {
type: MessageComponentTypes.Button,
label: "Button lable",
customId: "button-id"
}
(sorry i didn't ask, you are using v19 or v18? the above code is v19, if you are using v18 let me know that if that is the case i need to check the v18 codebase to see what you need to import)
for the select menu types it is the same, Typescript / autocomple should give you everything you need
v19
ok
thanks
to then send them you can use the components array in the methods for sendMessage and the ones for interactions
and remember the ActionRow
Does discord deno have displayAvatarURL() and IconUrl()?
I looked here and couldn't find it
you need to import them, give me a moment for the exact names
ok
avatarUrl for the user avatar
memberAvatarUrl for the member avatar (if you need it)
guildIconUrl for the guild icon
thanks
And do you need Action Row to use these components?
you do need to create the action row yes
so it is something like
{
components: [
{
type: MessageComponentTypes.ActionRow,
components: [
{
type: MessageComponentTypes.Button,
label: "Button lable",
customId: "button-id"
}
]
}
]
}
ok thanks
But that's when you send the messages, right?
wdym, components can be used when sending messages and when responding to interactions
member.memberAvatarUrl does not exist on type Member
you need to import those functions
they aren't a member of the objects
guildIconUrl(interaction.guildId, undefined, { size: 2048, format: "jpg" })
Error Argument of type
is not assignable to parameter of type
.
you need the guildId and hash of the image to get the icon url, idr if interaction.guild gives it, it might
also without the types, i'm not sure what is the TS error you sent
How do I get the hash of the image?
icon from the Guild object
ok
interaction.guild has a Partial Guild object, so it might have the icon hash
I resolve this error, but now apperead other error with embeds: Type
has no properties in common with type:
This code:
.setTitle(`${emojis.emojiduvida} | Support Dúvidas Mised`)
.setDescription(`${emojis.emojicerto} | Olá membros, então aqui é a parte onde vocês poderam tirar algumas dúvidas sobre o Mised com algumas perguntas frequentes, e por isso fizemos esse sistema com respostas prontas para sanar suas dúvidas. \n\n ${emojis.emojisetinha} | **Para tirar suas dúvidas selecione uns dos menus abaixo e siga as instruções do bot.**`)
.setColor(configs.color)
.setThumbnail(guildIconUrl(interaction.guildId, guild?.icon, { size: 2048, format: "jpg" }))
.setFooter(`Mised Support`)```
can you please include the actual types of the error? it is really difficult without
Type 'EmbedsBuilder' has no properties in common with type '{ title?: string | undefined; type?: EmbedTypes | undefined; description?: string | undefined; url?: string | undefined; color?: number | undefined; timestamp?: string | undefined; ... 6 more ...; fields?: { ...; }[] | undefined; }
are you doing { ..., embeds: [embedexplicação], ... } ? if so, just do { ..., embeds: embedexplicação, ... }
createEmebds() is already an array of embeds
(to add a new one use .newEmbed() and then use the .setXXXX methods to customize this other embed)
{ ..., embeds: [embedexplicação], ... }
ok
then remove the [ ] of the array, as it is already one (or spread the array, do whatever you need)
How do I start the bot now? Like what command do I give in the terminal to start it?
add the bot.start() (you can await it)
then just start the code with node/deno/bun
Is it to launch this node/deno/bun command in cmd?
bot.start() in the code
then you need to run the code with the runtime
Type 'Promise<string[]>' must have a 'Symbol.iterator' method that returns an iterator.
If you can help me with this file error, that's all that's missing.
const files = readdir(folder, { recursive: true })
for (const filename of files) {
if (!filename.endsWith('.js')) continue
// Using `file://` and `process.cwd()` to avoid weird issues with relative paths and/or Windows
await import(`file://${process.cwd()}/${folder}/${filename}`).catch((x) =>
logger.fatal(`Não foi possível importar o arquivo (${folder}/${filename}) for reason:`, x),
)
}```
await
to unwrap a Promise<T> you need await
Now this is new error: Uncaught (in promise) Error: ENOENT: no such file or directory, readdir
import { readdir } from 'node:fs/promises'
That's how it's imported
does the folder you are passing it to "readdir" exist?
the error is not about the import, is about what directory it is trying to read
yes
it comes from @types/nodes
quick note: functions in node:fs (node:fs/promises included) want a path relative to process.cwd(), not the file you are calling them from
so it would be like importing?
^ my mess above, does it exist relative to the CWD? (from where you are running node or whatever)
no. imports are relative to the file, readdir is relative to the CWD
yes
(CWD = Current Working Directory btw)
can you send the folder structure and what is that folder var set to? it might help as i'm not sure what is the issue if the folder exists
??????????????????????????????????????????????????
why the @types/node file for node:fs/promises?
I don't know either, I just know that it's the way to import the readdir
the import of readdir does not matter in any way for that error
it is about the first argument you are giving to readdir
He is being declared: declare module "fs/promises" {
Who argument?
you have readdir(folder, { recursive: true }) in the code you sent before, what is the value of folder when it errors?
A string
i meant when the code runs, the actual string, not the type
bot.logger.info('Loading commands...')
importDirectory('./dist/commands')
bot.logger.info('Loading events...')
importDirectory('./dist/events')```
does dist exist? usually it is created by something like tsc/swc/ecc
That's right, now the code works.
thanks
@pseudo sun So I'm using the advanced bot example from discord deno and it's not registering the slash commands, like I give the / there but it doesn't work. What do you think it could be?
i can't help with eris, i can help with discordeno if you need help with that
i do not know literally anything about eris
there is a different file that does the registering of commands: register-commands.ts
you need to run that, node dist/register-commands.js
But I don't have this file in the dist folder, in fact I don't even have the dist folder, I only have this file in the ts version.
the advanced example uses swc to compile, so it seems strage you don't have the dist folder
did you run the build script?
yes
this filename is .swcrc
?
that is the config file of swc yes
ok, how run this swc?
and in the package.json there is swc src --strip-leading-paths --delete-dir-on-start --out-dir dist under the build script (so if you are using yarn: yarn build, if you are using npm: npm run build, if you are using pnpm: pnpm build)
now is new error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Bruno Henrique\Desktop\mised-support-deno\dist\utils\updateCommands' imported from C:\Users\Bruno Henrique\Desktop\mised-support-deno\dist\register-commands.js
When I give node dist/register-commands.js
the error suggests you only compiled the register-commands file
And how do you solve it?
not sure, what did you run exacly to build?
Or did it work?
swc src --strip-leading-paths --delete-dir-on-start --out-dir dist
can you run dir /w dist ?
(assuming you are in cmd, else run ls dist if you are on powershell/anything else)
dir /w where?
from where you are running node
swc src --strip-leading-paths --delete-dir-on-start --out-dir dist this code?
in this directory you need to run the dir command C:\Users\Bruno Henrique\Desktop\mised-support-deno
I put it here and the same error remains
i meant, what is the output of that dir command
So it just moves on to the next cmd step as if nothing had happened.
so it is empty....
since i see PS at the beginning of the dir, can you try ls dist just to be sure?
^
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/08/2024 17:36 commands
d----- 10/08/2024 17:36 events
d----- 10/08/2024 17:36 interfaces
d----- 10/08/2024 17:36 utils
-a---- 10/08/2024 17:36 2220 bot.js
-a---- 10/08/2024 17:36 172 commands.js
-a---- 10/08/2024 17:36 393 config.js
-a---- 10/08/2024 17:36 297 index.js
-a---- 10/08/2024 17:36 194 register-commands.js```
ls dist\utils?
Diretório: C:\Users\Bruno Henrique\Desktop\mised-support-deno\dist\utils
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/08/2024 17:36 588 loader.js
-a---- 10/08/2024 17:36 733 permissions.js
-a---- 10/08/2024 17:36 200 updateCommands.js```
so the file exists, mhhh strange
then
can you try running again node dist/register-commands.js?
yes
i'm very much confused if it errors for a missing file
So it keeps giving this error when the file is there
can you runcat dist/register-commands.js? (cat gets the file content)
import { bot } from './bot.js';
import { updateApplicationCommands } from './utils/updateCommands';
bot.logger.info('Updating commands...');
updateApplicationCommands();```
can you open the file in vscode and add .js to the end of ./utils/updateCommands?
and then try running the file again
Same error
still the Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\Bruno Henrique\Desktop\mised-support-deno\dist\utils\updateCommands' imported from C:\Users\Bruno Henrique\Desktop\mised-support-deno\dist\register-commands.js? it should have a .js at the end of the utils\updateCommands now
It returns the updating commands but when I look in the bot and nothing happens I can't give the commands.
try reloading your client, slash command appear after a bit and reloading speeds that up
ok
so minute
It hasn't happened yet, but I'll wait here to see if it does.
thanks
i have just realized i'm very stupid, it is not your fault, but when i did the code i forgot a thing
whoops lol
give me a moment that i give you the code that should work
change the content of dist/register-commands.js with this: ```js
import 'dotenv/config';
import { bot } from './bot.js';
import importDirectory from './utils/loader.js';
import { updateApplicationCommands } from './utils/updateCommands.js';
bot.logger.info('Loading the commands')
await importDirectory('./dist/commands');
bot.logger.info('Updating commands...');
await updateApplicationCommands();
bot.logger.info('Done!');
// We need to exit explicitly or else the REST manager will keep NodeJS alive
process.exit();
I will do a PR tomorrow to fix the example(s) to use this code
Do I change it in ts too?
yes, it should be the same for this file
more error
application is not responding
in the console of the bot do you see any errors?
can you send the code for this msgduvimised command?
interactions have 3 seconds to respond, and if you defer you get 15 minutes
import { MessageComponentTypes, ApplicationCommandTypes, createEmbeds } from '@discordeno/bot';
import { createCommand } from '../commands.js';
import { bot } from '../bot.js';
import emojis from '../interfaces/emojis.js';
import { configs } from '../config.js';
createCommand({
name: 'msgduvidamised',
description: 'Envia a mensagem dúvidas do mised.',
type: ApplicationCommandTypes.ChatInput,
async execute (interaction) {
const menuzinpt = {
type: MessageComponentTypes.SelectMenu,
placeholder: `Selecione qual é a sua dúvida`,
customId: "menuzin_duvidas_mised",
options: [
{
label: `Como adicionar o Mised no seu servidor?`,
description: `Explicação de como adicionar o mised`,
emoji: {
id: BigInt(1269443633027743806),
name: "direita",
animated: true
},
value: "mised_add"
},
{
label: `Por que o Mised está offline`,
description: `Explicação o por que ele pode estar off`,
emoji: {
id: BigInt(1269443633027743806),
name: "direita",
animated: true
},
value: "mised_off"
},
{
label: `O Mised não responde aos meus comandos!`,
description: `Explicação caso o Mised não responda`,
emoji: {
id: BigInt(1269443633027743806),
name: "direita",
animated: true
},
value: "mised_notcommands"
},
{
label: `O Mised não defendeu meu servidor de um raid!`,
description: `Explicação sobre o sistema de defesa do mised`,
emoji: {
id: BigInt(1269443633027743806),
name: "direita",
animated: true
},
value: "mised_raid"
}
]
};
const guild = await bot.cache.guilds.get(BigInt(`${interaction.guildId}`));
let embedexplicação = createEmbeds().newEmbed().setTitle(`${emojis.emojiduvida} | Support Dúvidas Mised`).setDescription(`${emojis.emojicerto} | Olá membros, então aqui é a parte onde vocês poderam tirar algumas dúvidas sobre o Mised com algumas perguntas frequentes, e por isso fizemos esse sistema com respostas prontas para sanar suas dúvidas. \n\n ${emojis.emojisetinha} | **Para tirar suas dúvidas selecione uns dos menus abaixo e siga as instruções do bot.**`).setColor(configs.color).setThumbnail(configs.image).setFooter(`Mised Support`);
interaction.respond({
embeds: embedexplicação,
components: [
{
type: MessageComponentTypes.ActionRow,
components: [
menuzinpt
]
}
]
});
}
});
mhh, to me it seems that it should work so I'm kinda confused rn
I see
ohhhh, try removing the newEmbed() right after the createEmbeds()
(also make sure you are re-building the code each time you edit a .ts file)
ok
This error TypeError: (0 , node_perf_hooks_1.createHistogram) is not a functio when I run that swc command