我必须导入其他内容还是我犯了错误?
from telethon import functions, types, events, utils
from clases.button import Button
.
.
await client.send_message(chat_id,
'Pick one from this grid',
buttons=[[Button.inline('Left'),
Button.inline('Right')],
[Button.url('Check this site!', 'https://example.com')] ])
当我收到消息时,没有显示任何按钮
只有bot客户端可以发送buttons
。此外,什么是clases
?您试图从哪里导入Button
?
import asyncio
from telethon import TelegramClient
from telethon import functions, types, events
from telethon.tl.custom import Button
# start the bot client
client = TelegramClient('SESSION_NAME', 'YOUR_API_ID', 'YOUR_API_HASH')
client.start(bot_token='your bot token')
# function that sends the message
async def sendButtons():
await client.send_message(chat, 'Pick one from this grid', buttons=[[Button.inline('Left'), Button.inline('Right')], [Button.url('Check this site!', 'https://example.com')]])
# CallBackQuery event handler that gets triggered every time a user click a Button.inline
@events.register(events.CallbackQuery(chats=[your_chat]))
async def click_handler(event):
print(event) # event contains the user choice
loop = asyncio.get_event_loop()
loop.run_until_complete(sendButtons())
client.add_event_handler(click_handler)
loop.run_forever()
如果你有任何疑问,请查看Telethon文档,你会在那里找到答案。