Channel.send for slash commands - nextcord

Im migrating my commands to slash variants and for some i need to send message to a different channel,i need the await channel.send() in nextcord slash,something like
channel = client.get_channel(862547191373496380)
await interaction.response.channel.send_message()

You can still use
await channel.send()
Note that this will not respond to the slash command, but rather, send a separate message in the specified channel.

for the response, you can simply do this:
await channel.response.send_message()

Related

Python Telegram Bot - How to send JSON response.content as PDF file

With the conversational Bot, I need to hit a URL which returns a PDF file in response.content JSON. I want to send this file directly to the User without saving it on the server. How can this be done?
Sample Code:
response = requests.get(url)
pdf = open("pdffile.pdf", 'wb')
pdf.write(response.content)
pdf.close()
file = "pdffile.pdf"
update.message.reply_document(document=open(file, 'rb'))
I don't want to perfrom the write operation
As hinted in my comments above, you can pass a bytes stream to send_document. Here is minimal example based on your code snippet (plug in your bot token and your chat id):
import requests
from telegram import Bot
bot = Bot("TOKEN")
response = requests.get('https://python-telegram-bot.readthedocs.io/_/downloads/en/stable/pdf/')
bot.send_document(YOUR_CHAT_ID, document=response.content, filename='python-telegram-bot.pdf')
Note that I passed the filename parameter. This allows you to give a custom filename that will be displayed for the recipient.
Disclaimer: I'm currently the maintainer of python-telegram-bot.

Discord.py rewrite get list of members in guild

Just wondering how i would go about getting a list of all current members in a guild and then returning this as a message?
If you want to get the amount of members in specific guild, you can use len(guild.members). If you'd like to get list just use guild.members. If you want to send it, it might not work because Discord has max. 2000 characters in one message, but if your server is small then it should be good.
if you want to get the Member Count Use
guild.member_count where guild is the guild object
and if you want a list, you can iterate over guild.membersand append them

How to add a default text for unmatched intents on dialogflow?

If an intent fails, how can I assign it to a default text response?
Bot: what are you looking for?
Me: HakunakjewbfeuqcjBWGFUWG
Bot will not understand this and throws an error right there! I want to add a default text to this."I am not sure what you said.Can you say that again?"
How to do this?
I have tried fall back intent.it works only one time.So thats not a proper solution.
Any suggestion?
You have it correct - set a Fallback Intent. If you need a specific "no match" response to only some portions of your conversation, you can use a context to match those portions.
Use
Default fallback intent
To handle such ambiguous responses, you can set not only one but many different responses too which will appear randomly so the conversation's feel real too.
And Dialogflow has a default fall back Intent with pre-feeded Responses so all you have to do is enable it and train it according to your own phrases.
You might have added [LuisIntent("None")], to redirect not understood intents use [LuisIntent("")] and have desired default message in the following method.
Else
you can redirect such gibberish text to none intent
You can use a Default Fall Back intent or you could set an output context for the present intent to go to default fallback intent.

Ruby on Sinatra: Imitate a request based on a parameter

I am currently developing a Ruby API based on Sinatra. This API mostly receives GET requests from an existing social platform which supports external API integration.
The social platform fires off GET requests in the following format (only relevant parameters shown):
GET /{command}
Parameters: command and text
Where text is a string that the user has entered.
In my case, params[:text] is in fact a series of commands, delimited by a space. What I want to achieve is, for example: If params[:text]="corporate finance"
Then I want my API to interpret the request as a GET request to
/{command}/corporate/finance
instead of requesting /{command} with a string as a parameter containing the rest of the request.
Can this be achieved on my side? Nothing can be changed in terms of the initial request from the social platform.
EDIT: I think a better way of explaining what I am trying to achieve is the following:
GET /list?text=corporate finance
Should hit the same endpoint/route as
GET /list/corporate/finance
This must not affect the initial GET request from the social platform as it expects a response containing text to display to the user. Is there a neat, best practice way of doing this?
get "/" do {
text = params[:text].split.join "/"
redirect "#{params[:command]}/#{text}"
end
might do the trick. Didn't check though.
EDIT: ok, the before filter was stupid. Basically you could also route to "/" and then redirect. Or, even better:
get "/:command" do {
text = params[:text].split.join "/"
redirect "#{params[:command]}/#{text}"
}
There a many possible ways of achieving this. You should check the routes section of the sinatra docs (https://github.com/sinatra/sinatra)
The answer by three should do the trick, and to get around the fact that the filter will be invoked with every request, a conditional like this should do:
before do
if params[:text]
sub_commands = params[:text].split.join "/"
redirect "#{params[:command]}/#{sub_commands}"
end
end
I have tested it in a demo application and it seems to work fine.
The solution was to use the call! method.
I used a regular expression to intercept calls which match /something with no further parameters (i.e. /something/something else). I think this step can be done more elegantly.
From there, I split up my commands:
get %r{^\/\w+$} do
params[:text] ? sub_commands="/"+params[:text].split.join("/") : sub_commands=""
status, headers, body = call! env.merge("PATH_INFO" => "/#{params[:command]}#{sub_commands}")
[status, headers, body]
end
This achieves exactly what I needed, as it activates the correct endpoint, as if the URL was typed it the usual format i.e. /command/subcommand1/subcommand2 etc.
Sorry, I completely misunderstood your question, so I replace my answer with this:
require 'sinatra'
get '/list/?*' do
"yep"
end
like this, the following routes all lead to the same
You need to add a routine for each command or replace the command with a * and depend your output based on a case when.
The params entered by the user can be referred by the params hash.
http://localhost:4567/list
http://localhost:4567/list/corporate/finance
http://localhost:4567/list?text=corporate/finance

accessing request parameters Parse

I've got an issue when I try to access the request parameters.
As I've read, we have to use request.params.someParam to access the data we're sending via post or get. I'm following these steps, but I obtain an "undefined" response.
The code I use is the following one:
app.post('/hello', function(request, response) {
var query = new Parse.Query(Parse.Installation);
query.equalTo('UserName', request.params.userName); //trying to filter by UserName parameter
response.set('Content-Type', 'text/plain');
});
Does anyone know why do I obtain an undefined response and how to fix it?
Thanks
May I ask how do you specify your request params?
Because I found that when I tried to arrange a background job with request.params in Parse WebGUI, it requires to put a double quote (") for each key. Ex. {"userName":"John"}.
But when the request.params got passed into the background job, the double quote was escaped. Ex. {\"userName\": "John"}. So I can't get the param by request.params.userName
If I send the request via CURL then it all works fine.

Resources