I'm currently making a Discord bot using discord.py and I'm using a command tree to make slash commands, one of my files requires a file to be uploaded to the command, I know this is possible through discord as I have both seen it one before and done it in discord.js (I'm using python now as the bot links to something I have already made). But I can't seem to find anything on the internet or in the discord.py docs. Any clues as to how I might find this would be greatly appreciated, thanks in advance.
^Something like this is what I am talking about
Desired outcome: To have a slash command that a user is able to upload a file to
Tried so far: Reading the discord.py docs to see if it has a solution (it does not that I can find) and searching on the internet to see if there is anything even related to this (nothing that I have found).
Edit: I have found this that is related however it uses a different method of making slash commands and I have no method called "create_option".
(The method I am using):
import discord
commandTree = discord.app_commands.CommandTree(bot)
#commandTree.command(name="command", description="Some command")
async def some_command(interaction):
print("Something")
Annotate your argument with discord.Attachment.
...
async def some_command(interaction, file: discord.Attachment):
...
Related
I tried to create a slack application using the link, its working as /botname str.
is there any way that we could invoke application in slack using #botname str instead of /botname str. tried searching various places, couldn't get on how to do, can anyone help on it.
To use #botname instead of \botname, you'll need to change approach of implementation.
You need to implement by subscribing to 'Slack Events'.
This should help you to start:
https://api.slack.com/apis/connections/events-api
https://api.slack.com/events/app_mention
I'm trying to get emoji's from a another server.
I creates a server object for the server, it is a constant because I want to only pull from this server.
for emoji in main_tuple:
emoji_name_id =await server.fetch_emoji(emoji)
emoji_array.append(f"<{emoji_name_id.name.lower()}:{emoji_name_id.id}>")
error:
nextcord.ext.commands.errors.CommandInvokeError: Command raised an
exception: NotFound: 404 Not Found (error code: 10014): Unknown Emoji
I should mention I want to display it another server, I know this is probably obvious but yeah.
main_tuple is a directionary in a database that has the emoji id and name.
the error
Also the bot is part of the server it's getting the id from.
I have looked at: discord.py emoji all servers bot in
and it does not work for me.
First Issue, you are making a wrong reference.
<:Name:ID> and not <Name:ID> (if you don't see it, you missed the first colon)
Another issue,
emoji_name_id.name.lower()
Custom emojis are to have to have 'exact' name and ID as they have, by using lower method, you would be trying to reference a wrong custom emote.
For example:
The actual emote which might have the following reference <:ThisIsACoolEmote:ID>, while you are appending <:thisisacoolemote:ID> which doesn't exist
To mitigate this, you can just append str(emoji_name_id) which will automatically give you the correct emote reference which is in the format <:Name:ID:> and yes, it also will format animated emojis too, i.e:<a:Name:ID>
also fetching here might not be the best practice, you can use bot.get_emoji instead which gets emote from internal cache if you have access to member Privileged Intent.
So I stumbled upon a
cool feature
in Discord.
How can I use this “auto-predict” of sorts in my Discord.py bot?
I know its not the answer your looking for but to my knowledge discord.py doesn't support the / "auto-predict". These commands are only for discords in built methods
Edit: I have just learnt I have misinformed you, I was browsing a random server and found this:
You can see that "Steakbot" has added a /preset of its own. I'll look into how to do this
Edit 2 + Solution: It turns out in the discord dev settings for the bot under OAuth2 you can check this:
Here is the official discord documentation for implementing this including a python example:
https://discord.com/developers/docs/interactions/slash-commands
I wrote a small app returning routes with my public transport.
I'd like to package the app and use it via cli like: $ app_name start destination which is than handled by the app etc.
I've used the entry_points option in setup.py by defining an interface file, which is referenced when running the above code from command line.
However, I do not know if that's a best practice to accomplish that (as I have not found it on python.org.
So: What is a best practice to provide a cli?
An example I've seen:
with pytube you can do
$ pytube http://youtube.com/watch?v=9bZkp7q19f0 --itag=22
[EDIT:] thanks for the comments so far; they hint me to rephrase my question
I'm trying to write a script to automate a repetitive task I currently do manually. I would like to log in to a site remotely and inspect the returned page.
I've been doing this by sending a direct POST request (the site is PHP, I'm pretty sure it's Joomla) with my login details and data for the other fields of the form from the front page, but I'm getting either sockaddrinfo errors on the Net:HTTP Ruby library when I try a HTTP.post() (with data as a param=val1¶m2=val2 string), and a rejected redirect to home page if I use HTTP.post_form (using a Hash)
I'm willing to do this in any language, really, I just picked Ruby since it's a favorite for quick scripting. If you have any ideas in bash, Python, etc. I'd be happy to try it.
I've tried variations on some examples, to no avail. Have any of you tried something like this with success? Any stumbling blocks we beginners run into frequently?
Thanks for your time ^_^
-Paul
Try mechanize:
http://mechanize.rubyforge.org/mechanize/EXAMPLES_rdoc.html
Have a look at mechanize (Python) which is written with your problem in mind:
import re
from mechanize import Browser
br = Browser()
br.open("http://www.example.com/")
# follow second link with element text matching regular expression
response1 = br.follow_link(text_regex=r"cheese\s*shop", nr=1)