Turn Audio Download URL Into Attachment

thread title
11 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
elseif
elseifOP3y ago
14.5.0
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
elseif
elseifOP3y ago
that's usually for media links, no? like ones that link to an online file, not a download for said file i'll try it
Kinect3000
Kinect30003y ago
The url just has to be a direct link to the file
elseif
elseifOP3y ago
Kinect3000
Kinect30003y ago
It should work
elseif
elseifOP3y ago
k getting this error
CombinedError: Received one or more errors
at UnionValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1058:23)
at UnionValidator.parse (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:71:34)
at Object.execute (C:\Users\Owner\Desktop\VSCode\APISpam\commands\chirp.js:32:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errors: [
ValidationError: Expected undefined or null
at NullishValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:718:79)
at NullishValidator.run (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:71:34)
at Object.execute (C:\Users\Owner\Desktop\VSCode\APISpam\commands\chirp.js:32:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
validator: 's.nullish',
given: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-full.png'
},
CombinedError: Received one or more errors
at UnionValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1058:23)
at UnionValidator.parse (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:71:34)
at Object.execute (C:\Users\Owner\Desktop\VSCode\APISpam\commands\chirp.js:32:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errors: [
ValidationError: Expected undefined or null
at NullishValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:718:79)
at NullishValidator.run (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:71:34)
at Object.execute (C:\Users\Owner\Desktop\VSCode\APISpam\commands\chirp.js:32:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
validator: 's.nullish',
given: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-full.png'
},
ExpectedConstraintError: Invalid URL
at Object.run (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1562:27)
at StringValidator.run (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:103:27)
at UnionValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:71:34)
at Object.execute (C:\Users\Owner\Desktop\VSCode\APISpam\commands\chirp.js:32:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
constraint: 's.string.url',
given: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-full.png',
expected: 'expected to match an URL'
}
]
}
ExpectedConstraintError: Invalid URL
at Object.run (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1562:27)
at StringValidator.run (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:103:27)
at UnionValidator.handle (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at EmbedBuilder.setImage (C:\Users\Owner\Desktop\VSCode\APISpam\node_modules\@discordjs\builders\dist\messages\embed\Embed.cjs:71:34)
at Object.execute (C:\Users\Owner\Desktop\VSCode\APISpam\commands\chirp.js:32:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
constraint: 's.string.url',
given: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-full.png',
expected: 'expected to match an URL'
}
]
}
my code:
const fetch = require('node-fetch')
const color = require('../color.js')
const { EmbedBuilder, AttachmentBuilder } = require('discord.js')

const capFirst = str => {return str.charAt(0).toUpperCase() + str.slice(1)}

module.exports = {
name: 'chirp',
description: 'Gives you a recording of bird sounds.',
permissions: [],
usage: 'chirp',
async execute(interaction) {
interaction.deferReply()
let result = await fetch('https://xeno-canto.org/api/2/recordings?query=bird').then(res => res.json())
let recording = result.recordings[Math.floor(Math.random() * 500)]
console.log(recording)
const embed = new EmbedBuilder()
.setAuthor({name: 'Xeno Canto API', iconURL: 'https://i.guim.co.uk/img/media/f14bae8f215da78a9024bd2adf0b082a8763a994/0_604_5109_3066/master/5109.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=42ecea086441dc7308523f7b9eabc440'})
.setColor(color())
.setTimestamp()
.setTitle(`${recording.en} (${recording.also[0]})`)
.setFooter({text: `Requested by ${interaction.user.tag}`})
.setImage(result.file)
// .addFields(
// {name: 'Generic Name', value: recording.gen, inline: true},
// {name: 'Recordist', value: recording.rec, inline: true},
// {name: 'Locality', value: recording.loc, inline: true},
// {name: 'Country', value: recording.cnt, inline: true},
// {name: 'Sex', value: capFirst(recording.sex), inline: true},
// {name: 'Stage', value: capFirst(recording.stage), inline: true}
// )
.setImage(recording.sono.full)
// let attachment = new AttachmentBuilder('https://' + recording.file)

interaction.reply({embeds: [embed]/*, files: [attachment]*/})
}
}
const fetch = require('node-fetch')
const color = require('../color.js')
const { EmbedBuilder, AttachmentBuilder } = require('discord.js')

const capFirst = str => {return str.charAt(0).toUpperCase() + str.slice(1)}

module.exports = {
name: 'chirp',
description: 'Gives you a recording of bird sounds.',
permissions: [],
usage: 'chirp',
async execute(interaction) {
interaction.deferReply()
let result = await fetch('https://xeno-canto.org/api/2/recordings?query=bird').then(res => res.json())
let recording = result.recordings[Math.floor(Math.random() * 500)]
console.log(recording)
const embed = new EmbedBuilder()
.setAuthor({name: 'Xeno Canto API', iconURL: 'https://i.guim.co.uk/img/media/f14bae8f215da78a9024bd2adf0b082a8763a994/0_604_5109_3066/master/5109.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=42ecea086441dc7308523f7b9eabc440'})
.setColor(color())
.setTimestamp()
.setTitle(`${recording.en} (${recording.also[0]})`)
.setFooter({text: `Requested by ${interaction.user.tag}`})
.setImage(result.file)
// .addFields(
// {name: 'Generic Name', value: recording.gen, inline: true},
// {name: 'Recordist', value: recording.rec, inline: true},
// {name: 'Locality', value: recording.loc, inline: true},
// {name: 'Country', value: recording.cnt, inline: true},
// {name: 'Sex', value: capFirst(recording.sex), inline: true},
// {name: 'Stage', value: capFirst(recording.stage), inline: true}
// )
.setImage(recording.sono.full)
// let attachment = new AttachmentBuilder('https://' + recording.file)

interaction.reply({embeds: [embed]/*, files: [attachment]*/})
}
}
and my recording response
{
id: '86268',
gen: 'Steatornis',
sp: 'caripensis',
ssp: '',
group: 'birds',
en: 'Oilbird',
rec: 'Oswaldo Cortes',
cnt: 'Colombia',
loc: 'rio claro, antioquia',
lat: null,
lng: null,
alt: '1200',
type: 'song',
sex: '',
stage: '',
method: 'field recording',
url: '//xeno-canto.org/86268',
file: 'https://xeno-canto.org/86268/download',
'file-name': 'steatrsnisi.mp3',
sono: {
small: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-small.png',
med: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-med.png',
large: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-large.png',
full: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-full.png'
},
osci: {
small: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/wave/XC86268-small.png',
med: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/wave/XC86268-med.png',
large: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/wave/XC86268-large.png'
},
lic: '//creativecommons.org/licenses/by-nc-nd/2.5/',
q: 'D',
length: '0:11',
time: '08:00',
date: '2011-07-21',
uploaded: '2011-08-18',
also: [],
rmk: '',
'bird-seen': 'unknown',
'animal-seen': 'unknown',
'playback-used': 'unknown',
temp: '',
regnr: '',
auto: 'no',
dvc: '',
mic: '',
smp: '44100'
}
{
id: '86268',
gen: 'Steatornis',
sp: 'caripensis',
ssp: '',
group: 'birds',
en: 'Oilbird',
rec: 'Oswaldo Cortes',
cnt: 'Colombia',
loc: 'rio claro, antioquia',
lat: null,
lng: null,
alt: '1200',
type: 'song',
sex: '',
stage: '',
method: 'field recording',
url: '//xeno-canto.org/86268',
file: 'https://xeno-canto.org/86268/download',
'file-name': 'steatrsnisi.mp3',
sono: {
small: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-small.png',
med: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-med.png',
large: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-large.png',
full: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/ffts/XC86268-full.png'
},
osci: {
small: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/wave/XC86268-small.png',
med: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/wave/XC86268-med.png',
large: '//xeno-canto.org/sounds/uploaded/VVDRVZCVWW/wave/XC86268-large.png'
},
lic: '//creativecommons.org/licenses/by-nc-nd/2.5/',
q: 'D',
length: '0:11',
time: '08:00',
date: '2011-07-21',
uploaded: '2011-08-18',
also: [],
rmk: '',
'bird-seen': 'unknown',
'animal-seen': 'unknown',
'playback-used': 'unknown',
temp: '',
regnr: '',
auto: 'no',
dvc: '',
mic: '',
smp: '44100'
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30003y ago
You need the https part It looks like it’s not included in the full link
elseif
elseifOP3y ago
sickk
Want results from more Discord servers?
Add your server