mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
48 lines
14 KiB
HTML
48 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>SendMessageRequest</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link id="style" href="../../css/docs.dark.css" rel="stylesheet">
|
|
<script>
|
|
document.getElementById("style").href = "../../css/docs."
|
|
+ (localStorage.getItem("theme") || "light")
|
|
+ ".css";
|
|
</script>
|
|
<link href="https://fonts.googleapis.com/css?family=Nunito|Source+Code+Pro"
|
|
rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<div id="main_div"><ul class="horizontal"><li><a href="../../index.html">API</a></li><img src="../../img/arrow.svg" alt="/" /><li><a href="../index.html">Methods</a></li><img src="../../img/arrow.svg" alt="/" /><li><a href="index.html">Messages</a></li><img src="../../img/arrow.svg" alt="/" /><li><a href="send_message.html">SendMessageRequest</a></li></ul><h1>SendMessageRequest</h1><p><strong>Both users and bots</strong> can use this request. <a href="#examples">See code examples.</a></p><pre>---functions---
|
|
messages.sendMessage#983f9745 flags:# no_webpage:flags.1?<a href="../../index.html#true">true</a> silent:flags.5?<a href="../../index.html#true">true</a> background:flags.6?<a href="../../index.html#true">true</a> clear_draft:flags.7?<a href="../../index.html#true">true</a> noforwards:flags.14?<a href="../../index.html#true">true</a> update_stickersets_order:flags.15?<a href="../../index.html#true">true</a> invert_media:flags.16?<a href="../../index.html#true">true</a> allow_paid_floodskip:flags.19?<a href="../../index.html#true">true</a> peer:<a href="../../types/input_peer.html">InputPeer</a> reply_to:flags.0?<a href="../../types/input_reply_to.html">InputReplyTo</a> message:<a href="../../index.html#string">string</a> random_id:<a href="../../index.html#long">long</a> reply_markup:flags.2?<a href="../../types/reply_markup.html">ReplyMarkup</a> entities:flags.3?<a href="../../index.html#vector">Vector</a><<a href="../../types/message_entity.html">MessageEntity</a>> schedule_date:flags.10?<a href="../../index.html#date">date</a> send_as:flags.13?<a href="../../types/input_peer.html">InputPeer</a> quick_reply_shortcut:flags.17?<a href="../../types/input_quick_reply_shortcut.html">InputQuickReplyShortcut</a> effect:flags.18?<a href="../../index.html#long">long</a> = <a href="../../types/updates.html">Updates</a></pre><button onclick="cp('from telethon.tl.functions.messages import SendMessageRequest');">Copy import to the clipboard</button><h3>Returns</h3><table><tr><td><a href="../../types/updates.html">Updates</a></td></tr></table><p>This type can be an instance of either:</p><table><tr><td><a href="../../constructors/update_short.html">UpdateShort</a></td><td><a href="../../constructors/update_short_chat_message.html">UpdateShortChatMessage</a></td></tr><tr><td><a href="../../constructors/update_short_message.html">UpdateShortMessage</a></td><td><a href="../../constructors/update_short_sent_message.html">UpdateShortSentMessage</a></td></tr><tr><td><a href="../../constructors/updates.html">Updates</a></td><td><a href="../../constructors/updates_combined.html">UpdatesCombined</a></td></tr><tr><td><a href="../../constructors/updates_too_long.html">UpdatesTooLong</a></td></tr></table><h3>Parameters</h3><table><tr><td><b>peer</b></td><td style="text-align:center"><a href="../../types/input_peer.html">InputPeer</a></td><td>Anything entity-like will work if the library can find its <code>Input</code> version (e.g., usernames, <code>Peer</code>, <code>User</code> or <code>Channel</code> objects, etc.).</td></tr><tr><td><b>message</b></td><td style="text-align:center"><a href="../../index.html#string">string</a></td><td></td></tr><tr><td><b>no_webpage</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>silent</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>background</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>clear_draft</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>noforwards</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>update_stickersets_order</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>invert_media</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>allow_paid_floodskip</b></td><td style="text-align:center"><a href="../../index.html#true">flag</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>reply_to</b></td><td style="text-align:center"><a href="../../types/input_reply_to.html">InputReplyTo</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>random_id</b></td><td style="text-align:center"><a href="../../index.html#long">long</a></td><td>If left unspecified, it will be inferred automatically.</td></tr><tr><td><b>reply_markup</b></td><td style="text-align:center"><a href="../../types/reply_markup.html">ReplyMarkup</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>entities</b></td><td style="text-align:center"><a href="../../types/message_entity.html">MessageEntity</a></td><td>This argument defaults to <code>None</code> and can be omitted. Otherwise, a <span class="tooltip" title="Any iterable that supports len() will work too">list</span> must be supplied.</td></tr><tr><td><b>schedule_date</b></td><td style="text-align:center"><a href="../../index.html#date">date</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>send_as</b></td><td style="text-align:center"><a href="../../types/input_peer.html">InputPeer</a></td><td>This argument defaults to <code>None</code> and can be omitted. Anything entity-like will work if the library can find its <code>Input</code> version (e.g., usernames, <code>Peer</code>, <code>User</code> or <code>Channel</code> objects, etc.).</td></tr><tr><td><b>quick_reply_shortcut</b></td><td style="text-align:center"><a href="../../types/input_quick_reply_shortcut.html">InputQuickReplyShortcut</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr><tr><td><b>effect</b></td><td style="text-align:center"><a href="../../index.html#long">long</a></td><td>This argument defaults to <code>None</code> and can be omitted.</td></tr></table><h1>Known RPC errors</h1><p>This request can cause 33 known errors:</p><table><tr><td><code>AuthKeyDuplicatedError</code></td><td>The authorization key (session file) was used under two different IP addresses simultaneously, and can no longer be used. Use the same session exclusively, or use different sessions.</td></tr><tr><td><code>BotDomainInvalidError</code></td><td>The domain used for the auth button does not match the one configured in @BotFather.</td></tr><tr><td><code>ButtonDataInvalidError</code></td><td>The provided button data is invalid.</td></tr><tr><td><code>ButtonTypeInvalidError</code></td><td>The type of one of the buttons you provided is invalid.</td></tr><tr><td><code>ButtonUrlInvalidError</code></td><td>Button URL invalid.</td></tr><tr><td><code>ChannelInvalidError</code></td><td>Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited.</td></tr><tr><td><code>ChannelPrivateError</code></td><td>The channel specified is private and you lack permission to access it. Another reason may be that you were banned from it.</td></tr><tr><td><code>ChatAdminRequiredError</code></td><td>Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group.</td></tr><tr><td><code>ChatIdInvalidError</code></td><td>Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead.</td></tr><tr><td><code>ChatRestrictedError</code></td><td>The chat is restricted and cannot be used in that request.</td></tr><tr><td><code>ChatWriteForbiddenError</code></td><td>You can't write in this chat.</td></tr><tr><td><code>EntitiesTooLongError</code></td><td>It is no longer possible to send such long data inside entity tags (for example inline text URLs).</td></tr><tr><td><code>EntityBoundsInvalidError</code></td><td>Some of provided entities have invalid bounds (length is zero or out of the boundaries of the string).</td></tr><tr><td><code>EntityMentionUserInvalidError</code></td><td>You can't use this entity.</td></tr><tr><td><code>InputUserDeactivatedError</code></td><td>The specified user was deleted.</td></tr><tr><td><code>MessageEmptyError</code></td><td>Empty or invalid UTF-8 message was sent.</td></tr><tr><td><code>MessageTooLongError</code></td><td>Message was too long.</td></tr><tr><td><code>MsgIdInvalidError</code></td><td>The message ID used in the peer was invalid.</td></tr><tr><td><code>PeerIdInvalidError</code></td><td>An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations).</td></tr><tr><td><code>PollOptionInvalidError</code></td><td>A poll option used invalid data (the data may be too long).</td></tr><tr><td><code>RandomIdDuplicateError</code></td><td>You provided a random ID that was already used.</td></tr><tr><td><code>ReplyMarkupInvalidError</code></td><td>The provided reply markup is invalid.</td></tr><tr><td><code>ReplyMarkupTooLongError</code></td><td>The data embedded in the reply markup buttons was too much.</td></tr><tr><td><code>ScheduleBotNotAllowedError</code></td><td>Bots are not allowed to schedule messages.</td></tr><tr><td><code>ScheduleDateTooLateError</code></td><td>The date you tried to schedule is too far in the future (last known limit of 1 year and a few hours).</td></tr><tr><td><code>ScheduleStatusPrivateError</code></td><td>You cannot schedule a message until the person comes online if their privacy does not show this information.</td></tr><tr><td><code>ScheduleTooMuchError</code></td><td>You cannot schedule more messages in this chat (last known limit of 100 per chat).</td></tr><tr><td><code>TimeoutError</code></td><td>A timeout occurred while fetching data from the worker.</td></tr><tr><td><code>TopicDeletedError</code></td><td>The topic was deleted.</td></tr><tr><td><code>UserBannedInChannelError</code></td><td>You're banned from sending messages in supergroups/channels.</td></tr><tr><td><code>UserIsBlockedError</code></td><td>User is blocked.</td></tr><tr><td><code>UserIsBotError</code></td><td>Bots can't send messages to other bots.</td></tr><tr><td><code>YouBlockedUserError</code></td><td>You blocked this user.</td></tr></table><p>You can import these from <code>telethon.errors</code>.</p><h1 id="examples">Example</h1><p>Please refer to the documentation of <a href="https://docs.telethon.dev/en/stable/modules/client.html#telethon.client.messages.MessageMethods.send_message"><code>client.send_message()</code></a> to learn about the parameters and see several code examples on how to use it.</p><p>The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.</p><details><pre><strong>from</strong> telethon.sync <strong>import</strong> TelegramClient
|
|
<strong>from</strong> telethon <strong>import</strong> functions, types
|
|
|
|
<strong>with</strong> TelegramClient(name, api_id, api_hash) <strong>as</strong> client:
|
|
result = client(functions.messages.SendMessageRequest(
|
|
peer=<em>'username'</em>,
|
|
message=<em>'Hello there!'</em>,
|
|
no_webpage=<strong>True</strong>,
|
|
noforwards=<strong>True</strong>,
|
|
update_stickersets_order=<strong>True</strong>,
|
|
invert_media=<strong>True</strong>,
|
|
allow_paid_floodskip=<strong>True</strong>,
|
|
reply_to=types.InputReplyToMessage(
|
|
reply_to_msg_id=42,
|
|
top_msg_id=42,
|
|
reply_to_peer_id=<em>'username'</em>,
|
|
quote_text=<em>'some string here'</em>,
|
|
quote_entities=[types.MessageEntityUnknown(
|
|
offset=42,
|
|
length=42
|
|
)],
|
|
quote_offset=42
|
|
),
|
|
schedule_date=datetime.datetime(2018, 6, 25),
|
|
send_as=<em>'username'</em>,
|
|
quick_reply_shortcut=types.InputQuickReplyShortcut(
|
|
shortcut=<em>'some string here'</em>
|
|
),
|
|
effect=-12398745604826
|
|
))
|
|
print(result.stringify())</pre></details><textarea id="c" class="invisible"></textarea><script>function cp(t){var c=document.getElementById("c");c.value=t;c.select();try{document.execCommand("copy")}catch(e){}}</script></div><script>prependPath = "../../";</script><script src="../../js/search.js"></script></body></html> |