Discord music bot, execute a play command with multiple songs in it - discord.js

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.

Related

Discord.js - Getting additional Text from Slash Command

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.

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.

Avoid rate limit for changing voice channel name discord js 13

I'm trying to create a slash command using discord.js v13 to change the names of voice channels. I am using this code to do this :
module.exports = {
data: new SlashCommandBuilder()
.setName('name')
.setDescription('Set name for your voice channel')
.addStringOption(option => option.setName('name').setDescription('Enter your name').setRequired(true)),
async execute(interaction) {
const name = interaction.options.getString('name');
if (!interaction.member.voice.channel) await interaction.reply('Error not in a voice channel!');
else {
await interaction.member.voice.channel.setName(name);
await interaction.reply('Done!');
}
},
};
This code is fine and makes the job done. But as you know I can change the voice channel's name only 2 times per 10 minutes because of the limit rate. So if a user tries to change the voice channel's name for the third time, I won't get any error on the console, and discord js will queue this request for later and will do it after 10 minutes. But the user gets this error on discord: This interaction failed.
I want to check if there was a rate limit for my request, and if is, don't send the request and just reply to the user. Is this possible?
There is no inherent functionality that is able to handle the situation in the way you want it to, but the problem is soluble using regular old JavaScript. For example, you could use an integer to indicate how many times the command has been used and use setTimeout() to decrement it 10 minutes after the command was called. That way you can check if the int is equal to 2 in which case you skip the .setName().
There are undoubtedly other ways to implement the same or similar behavior, but, to answer your question, unfortunately the discordjs/voice library does not provide any simple way to do it.

how to make a discord bot mention someone in a specific channel (discord.js)

im making a "mini game chat bot" and i want the bot to have different endings.
when someone unlocks an ending i would like to be notified so i can keep track of how many endings that person has unlocked (no i wont add roles to keep track because if my calculations are correct the bot will have like 200 different endings).
i want to make it so that,
for example, someone says B3 in #general and the bot answers in #endings
#(person who used the command) unlocked the ending "I probably
shouldn't have said that..."
case 'B3':
message.channel.send('Umm.. What?');
const B3ending = new Discord.MessageEmbed()
.setTitle('Congratulations!)
.setColor(0x8CF1EC)
.setDescription('You unlocked the ending "I probably shouldn't have said that..."');
message.channel.send(B3ending);
break;
Well first you would need to get the channel somehow, maybe by id:
const endChannel = message.guild.channels.cache.get(id);
After that you can just use the send method alongside msg.author
endChannel.send(`${message.author} here's the ending`, { embed: B3ending });

Deleting certain file type attachments in a specific channel?

I'm trying to add certain files from being posted to the general channel as we have designated channels for certain attachments, clips, videos, music, etc. I'm fine on getting the bot to recognize links, however, having a hard time getting it to recognize attachments, more specifically, .mp4 attachments.
I added a whitelist of acceptable attachments in an array, then try and check the message author attachment to see if it's okay to post, if its an .mp4 it should be deleted.
The try function is within the on_message event decorator.
whiteList = ['bmp','jpeg','jpg','png']
try:
for attachment in message.attachments:
#Get general channel ID
channel = client.get_channel(521376573245358081)
if message.channel is channel and attachment['filename'].split('.')[-1] not in whiteList:
await message.delete()
botsMessage = await channel.send("{0.mention} Please refrain from posting videos in General. You may post them in #videos".format(message.author))
await asyncio.sleep(5)
await botsMessage.delete()
except:
print('Unknown error')
No error comes of this as when I test this the attachment remains, the bot passes over the function and prints the console message (used for debugging to make sure the code reaches that far). Any suggestions?
attachment['filename'].split('.')[-1]
You treated attachment as an dictionary that has a key called filename.
You should have treated attachment as an object that has a property called filename as follows:
attachment.filename.split('.')[-1]
Also, you should break the loop whenever the message is deleted,
# ...
botsMessage = await channel.send("{0.mention} Please refrain from posting videos in General. You may post them in #videos".format(message.author))
await asyncio.sleep(5)
await botsMessage.delete()
break
# ...
in the event that the user have sent mutiple video files, the loop will still continue even after you delete the message. Which may cause it to try to delete a deleted message
The break statement prevents the above from happening.

Resources