Discord.js - Getting additional Text from Slash Command - discord.js

When writing a Discord.js Slash Command, is it possible to get the text that was entered "outside" of the defined options?
Let's say I have the following SlashCommand defined:
new SlashCommandBuilder()
.setName('slashtest')
.addStringOption(option => option.setName('name').setDescription('Test Option').setRequired(true))
.addStringOption(option => option.setName('text').setDescription('Second Option').setRequired(true)),
In this example I would like to get the text "Even more Stuff"

According to the discord.js documentation and the discord developer documentation, you can only get user input from the command options in the discord slash command 'handler' (the menu that pops up when you enter '/').
From my past experience of using slash commands, I don't believe it's possible to retrieve user input outside of options. I guess you could create more options for more specific user input.

Related

Discord music bot, execute a play command with multiple songs in it

I followed a tutorial for a JavaScript discord music bot and have been modifying it some, I attempted to get YouTube playlist URLs to work but they never did, so I decided to try to give the play command the option to execute multiple values. I am not sure where to begin on this. The play command as is is very simple:
module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("a test of a better more streamlined play command")
.addStringOption((option) => option.setName("searchterm").setDescription("the song's url or the title/artist").setRequired(true))
,
There is code to search for music based on URL or key words and add it to the queue further down.
as is, if I do /play song1, song2 it ignores all previous values and searches for only the last value I entered.

Get GuildMember by UserId in discord.js v13 Slash Command

I've searched a lot of data so far, but I can't find any code that works. Can you tell me the code you get?
This is how I register Slash Command.
client.api.applications(client.user.id).guilds(guild).commands.post({
data: {
name: command.name,
description: command.description,
options: command.options
}
});
I'm Korean, so I wrote a translator.
To get the GuidMember details of the user by the user's id, you would first have to fetch the guild id, then you can use client.guilds.cache.get(guildid).members.cache.get(userid). But since you are doing this in a slash command, you would receive an Interaction object when the user uses the slash command, so then you can just use interaction.guild.members.cache.get(userid). If you want to get the GuildMember details of the user who ran the slash command, then you can just use const guildmember = interaction.member

Discord.js Slash Command permissions

I want to create Slash Command Permissions on my Bot, so that the Command is grey for those who don´t have permissions for the Command, but I don´t find anything usefull for this problem.
I using the Command-Handler from discordjs.guide
This is my Code
Sorry, I may not help you, but I do not know the exact answer to your question, but I suggest you to use Worm Off Keys, using it is very easy, You can set permission in the command file by using permissions: ['ADMINISTRATOR'], in the command properties, and you can get/reply to the user in easy way:
const user = message : message ? interaction;
user.reply({ content: "properties test" })
This is just an example.

How to add reactions to messages in discord.py without id

I am new to discord.py coding. I can't find the I'd for arrow up emoji... I've tried client.emojis and others but it doesnt work... pls help or send me all the ids or a website to see all the ids
just type your emoji in :this: form and stic an \ before the emojiname thats it!
when you send it it will come as <:something:1234567890123>
copy the numbers at the end thats your emoji id
same can be done with members and channels just instead of :this: do :#random_dude: and for channels do #general
hope this helps! Goodluck on your development!
I'm not sure what your code looks like, but if you're interacting with your 'message' asyncs you could do this.
emoji = '\N{THUMBS UP SIGN}'
# or '\U0001f44d' or '👍'
await message.add_reaction(emoji)
If you can, can you add your code so I can see where your error might be?
As zjbrown said, the thumbs up emoji can be stored in a string (and sent) using "\N{THUMBS UP SIGN}", "\U0001f44d", or "👍".
You can google a built-in emoji's name to find websites that have emoji descriptions. Sometimes these sites also have the unicode name, but this is not guranteed. If you want to send a custom emoji, you will have to find the emoji's id.
For built-in emojis, you can use RoboDanny's charinfo command (you'll have to add it to your own bot or use the RoboDanny bot in the discord.py support server) to get the unicode name.
If it is a custom emoji, you can send it in chat and get the image url (right click -> copy url). Then, look for the string of numbers before the .png and copy that. (Numbers only - don't copy the beginning of the url!) You can then send custom emojis by using the string <:[emoji name]:[emoji id]> for static emojis and <a:[emoji name]:[emoji id]> for animated emojis.

How can I properly upload too long messages as a file?

I was doing some research on Discord's capabilities today, and then I noticed that the "upload as file" option is given when a message is more than 2000 characters long.
The number plays a role here, but my statement can also be wrong, the fact is that some things are posted only as a link and or then not sent at all if I raise >2000.
Here now the problem:
I am requesting data from Genius for a lyrics command. I already have some kind of override built in for when len(data["lyrics"]) is greater than 2000 "characters", that should be Discord's limit after all, otherwise the bot wouldn't be able to process the embed I am trying to send.
How can I manage that lyrics >2000 are sent as a file?
Relevant code:
if len(data["lyrics"]) > 2000:
return await ctx.send(f"<{data['links']['genius']}>"))
This is the normal request, it works too, but it just throws out the link.
I then tried to send this via discord.File with the corresponding piece of code above, does not work. (Something like file=discord.File(data) was tried too!)
Something like ctx.file.send does not work in this case either
The following posts were viewed:
Uploading a file in a embed discord.py (not a image)
Discord.py - Sending a text file on DM
Discord.py Bot sending file to Discord Channel
Python discord.py ways to split output to bypass 2000 character limit
What I want my bot to do if data["lyrics"] > 2000:
You can save the text into a io.StringIO buffer and pass that into the discord.File constructor:
from io import StringIO
text = data["lyrics"]
if len(text) > 2000:
buffer = StringIO(text)
f = discord.File(buffer, filename="lyrics.txt")
await ctx.send(file=f)

Resources