sorry I'm late, I overslept. uh, please send a song in discord. submissions may be written in languages with support for networking.
the API endpoint Create Message (POST https://discord.com/api/v10/channels/{channel.id}/messages) allows bot accounts to send messages on Discord. you'll need these headers for your request to go through:
you can use the content field in the body to include a link to a song ({"content": "https://soundcloud.com/100gecs/757a1"}). if you would like to send it as an attachment, the request should be a multipart/form-data request including a files[0] file:
...
Content-Type: multipart/form-data; boundary=mjauuuu
--mjauuuu
Content-Disposition: form-data; name="content"
here is your song I made it for you
--mjauuuu
Content-Disposition: form-data; name="files[0]"; filename="yoursong.ogg"
Content-Type: audio/ogg
[audio bytes]
--mjauuuu--
if you like, you can send the rest of the request as ordinary JSON while doing this using a key named payload_json:
...
Content-Type: multipart/form-data; boundary=mjauuuu
--mjauuuu
Content-Disposition: form-data; name="payload_json"
Content-Type: application/json
{
"embeds": [{
"title": "wow!",
"description": "look at this song I made for you :heart:"
}]
}
--mjauuuu
Content-Disposition: form-data; name="files[0]"; filename="yoursong.ogg"
Content-Type: audio/ogg
[audio bytes]
--mjauuuu--
your challenge, given a bot token and the ID of a channel it can send to, is to send a song to that channel. as most languages are allowed, and the prompt is somewhat open-ended, there is no fixed API.
importosimportrequestst='bottoken'c='channelid'n='The Most Wanted Person In The United States.mp3'f=open(n,'rb')h={'authorization':'Bot '+t}s=os.path.getsize(n)u='https://discord.com/api/v10/channels/'+str(c)+'/messages'a='https://discord.com/api/v10/channels/'+str(c)+'/attachments'l={"files":[{"filename":n,"file_size":s,"id":"0"}]}r=requests.post(a,headers=h,json=l)o=r.json()['attachments'][0]['upload_url']m=r.json()['attachments'][0]['upload_filename']d={'Content-Length':str(s),'Connection':'keep-alive','Content-Type':'audio/mp3','authorization':'Bot '+t}p=requests.put(o,headers=d,data=f)i={"attachments":[{"id":"0","filename":n,"uploaded_filename":m}]}p=requests.post(u,headers=h,json=i)f.close()
# This example requires the 'message_content' intent.importdiscordintents=discord.Intents.default()intents.message_content=Trueclient=discord.Client(intents=intents)@client.eventasyncdefon_ready():print(f'We have logged in as {client.user}')@client.eventasyncdefon_message(message):ifmessage.author==client.user:returnifmessage.content.startswith("$song"):awaitmessage.channel.send("https://www.youtube.com/watch?v=dsuJZx24V_A")client.run("NzUyOTI0MTA5ODk3MjAzODcz.GlP4tR.9HigYa2kwGXaLaW06ngZKpklVdb6mHT55ng2is")
post a comment