I want that when you use the command webhook should send the message in the channel where the code is used.But I dont know how to do it please help.
#bot.command()
async def deneme(ctx, test):
webhook = Webhook.partial(webhookid, webhooktoken, adapter=RequestsWebhookAdapter())
webhook.send(test, username=ctx.author.name, avatar_url=ctx.author.avatar_url)
If your channel already has a created webhook you can get a list of all of the webhook of the channel the message is sent in by using ctx.channel.webhooks() picking one and getting its url by doing WEBHOOK.url(). If your channel does not have a webhook you can create one by using await ctx.channel.create_webhook(name='WEBHOOK NAME') you can assign this to a variable and get the url by using WEBHOOK.url().
NOTE: Creating a webhook is only supported by discord.py-rewrite.
Alternatively you can just use your bot to reply instead of using a webhook by using ctx.channel.send()
Related
I tried to send alerts from Sumologic to Slack. But when I test the connection, it always failed and return 400 http code. I used the connection type as Webhook
When test the connection, it should pass
If you are using WebHook and testing the connection, you must use a valid payload. If you don't provide a valid payload, the connection test will not succeed.
You can use the connection type as SLACK over WebHook. Still, you are using a webhook URL.
This link shows how to integrate Sumologic with Slack.
https://www.youtube.com/watch?v=qEz8dcp9SgI
I have a doubt, in a group chat system that has a database with a rest API, who should issue the event of a new message?
The client or the endpoint to create the new message?
For example: X user sends a message to group Y, then uses the api endpoint api.com/message-create and that endpoint emits the message-create event through websocket
Example 2: X user sends a message to group Y, then uses the api api.com/message-create endpoint and the endpoint does not emit the message-create event, but was emitted when the user pressed the send message button
I still don't quite understand if it would occupy more websocket channels to achieve that, if a global one is enough, etc.
The server should be responsible for communication logic. So your first example is better.
But: why do you use two communication channels for sending an creating messages?
If you use websocket, you don't need create a message from a client by using additional rest endpoint.
This approach is prone to errors. For example if the client will loose network connection after sending message through websocket and before executing call to the REST endpoint?
The message will not be stored in a database.
Your flow should looks as follows:
User clicks the send button.
Message is send through the websocket.
Message is stored in the database asynchronously (you can do it directly from communication server, or use rest endpoint)
Emit "new message" event to the group.
I have a problem trying to get a webhook to interact with a bot
For some reason, the bot doesn't respond to commands initiated by the webhook
Is there a way to make sure it initiates?
It works normally otherwise
My command:
# registering new commands that can be called by the flask webhook
#client.command()
async def new_message_received(ctx, trade_hash: str = ''):
print(f'New Trade Received! {trade_hash}')
paxful_cogs = client.get_cog('Paxful_Cogs')
await paxful_cogs.new_trade_received(trade_hash=trade_hash)
await ctx.send(f'{trade_hash} executed.')
print(f'Trade Done Execution! {trade_hash}')
My webhooks are sent successfully, but the bot does not respond to them.
Bot Responds to Me, but not to webhook.
Okay, figured it out with a lot of help from the python discord server.
#client.event
async def on_message(message):
# Manually get the invocation context from the message
ctx = await client.get_context(message)
# Verify that the context has a command and can be used
if ctx.valid:
# Invoke the command using the earlier defined bot/client/command
await client.invoke(ctx)
https://i.gyazo.com/d23edb65efeeaa834c5de33d70f00484.png
Basically, we're overriding the on_message fx, checking to see if the message matches our prefix/command structure with ctx.valid and then forcing the command to be processed with client.invoke(ctx) regardless if it's from a bot/webhook or not.
I have a Twilio messaging service with Copilot and the sticky sender feature enabled.
I would like to view the phone number that Copilot assigns to my recipients when I send them a message.
With the Ruby client, I get a MessageContext object when I send a message, but it only has the
messaging service SID - the from method returns nil.
Currently, this is how I'm sending messages:
def send(from, to, message)
client = Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN)
client.api.account.messages.create(
body: message,
messaging_service_sid: from,
to: to,
status_callback: BASE_URL + '/sms_status/status',
)
end
Twilio developer evangelist here.
I'm not sure, but you might not have the phone number at the time you make the API request using a messaging service. This request really just queues up the message to be sent.
I would check the message object once it has been sent. You have a status callback URL setup, so you should be able to either inspect the parameters sent to that URL or look up the message from the API using its SID and then get the number that was used.
I want to create a command in discord.py that sends me a dm with a suggestion attached to it. Or it should post the request in my discord log channel. Unfortunatly i have absolutly no clue how to do this.
To send a message to a specific channel:
await bot.send_message(discord.Object(id='INSERT CHANNEL ID HERE'), 'INSERT MESSAGE CONTENT HERE')
To send a direct message to yourself:
user = await bot.get_user_info('INSERT YOUR ID HERE')
await bot.send_message(user, 'INSERT MESSAGE CONTENT HERE')