在使用命令并将该消息存储为变量(pyrogram)之后,如何从聊天中获取消息?

发布于 2025-02-02 05:48:47 字数 2385 浏览 3 评论 0原文

因此,我有点新的pyrogram,我想创建自己的Genshin机器人。使用命令兑换代码后,我希望将消息传达并存储为变量。因此,任何人都可以在将代码作为用户输入之后帮助我

,我可以使用Genshin.py API包装器来兑换代码。只需要帮助获取消息并将其存储为可变即可。


import genshin
import os
from dotenv import load_dotenv
from pyrogram import Client, filters
load_dotenv()

global chatid
chatid = 842544591

global uid
uid = os.getenv("uid")
ltuid = os.getenv("ltuid")
ltoken = os.getenv("ltoken")
cookie_token = os.getenv("cookie_token")
api_id = os.getenv("api_id")
api_hash = os.getenv("api_hash")
bot_token = os.getenv("bot_token")

cookies = {"ltuid": ltuid,
           "ltoken": ltoken,
           "cookie_token": cookie_token,
           "uid": uid}
client = genshin.Client(cookies)

bot = Client(
    "Genshin Bot",
    api_id=api_id,
    api_hash=api_hash,
    bot_token=bot_token
)


@bot.on_message(filters.command('start'))
def start_command(bot, message):
    message.reply_text(
        "Welcome to Genshin Auto Tasks Bot.\nFor Getting Started Use /help command.")


@bot.on_message(filters.command('help'))
def help_command(bot, message):
    message.reply_text("This is Bot's Help Section")


@bot.on_message(filters.command('notes'))
async def get_notes(bot, message):
    data = await client.get_full_genshin_user(uid)
    notes = await client.get_notes(uid)
    active_days = (data.stats.days_active)
    total_characters = (data.stats.characters)
    abyss_total_stars = (data.abyss.previous.total_stars)
    resin_count = notes.current_resin
    resin_recovery_time = notes.remaining_resin_recovery_time
    await message.reply_text("Pranay Asia" + "\n" +
                             "uid : " + str(uid) + "\n" +
                             "-----------------------------------------------------------------" + "\n" +
                             "Resin Count: " + str(resin_count) + "/" + str(notes.max_resin) + "\n" +
                             "Countdown to next resin recovery: " + str(resin_recovery_time) + "\n" +
                             "Total No. of Active Days: " + str(active_days) + "\n" +
                             "Total No. of Characters: " + str(total_characters) + "\n" +
                             "Total Stars in Abyss: " + str(abyss_total_stars)
                             )


@bot.on_message(filters.command('redeemcode'))
def redeem_code(bot, message):
    message.reply_text("Send the Code to Redeem")


bot.run()

So I am kinda new with Pyrogram and I want to create my own Genshin Bot. After using the command redeem code, I want the message to be taken and stored as variable. so can anyone help me with that

after taking the code as input from user I would be able to use genshin.py api wrapper to redeem code. Just need help with getting message and storing it as variable.


import genshin
import os
from dotenv import load_dotenv
from pyrogram import Client, filters
load_dotenv()

global chatid
chatid = 842544591

global uid
uid = os.getenv("uid")
ltuid = os.getenv("ltuid")
ltoken = os.getenv("ltoken")
cookie_token = os.getenv("cookie_token")
api_id = os.getenv("api_id")
api_hash = os.getenv("api_hash")
bot_token = os.getenv("bot_token")

cookies = {"ltuid": ltuid,
           "ltoken": ltoken,
           "cookie_token": cookie_token,
           "uid": uid}
client = genshin.Client(cookies)

bot = Client(
    "Genshin Bot",
    api_id=api_id,
    api_hash=api_hash,
    bot_token=bot_token
)


@bot.on_message(filters.command('start'))
def start_command(bot, message):
    message.reply_text(
        "Welcome to Genshin Auto Tasks Bot.\nFor Getting Started Use /help command.")


@bot.on_message(filters.command('help'))
def help_command(bot, message):
    message.reply_text("This is Bot's Help Section")


@bot.on_message(filters.command('notes'))
async def get_notes(bot, message):
    data = await client.get_full_genshin_user(uid)
    notes = await client.get_notes(uid)
    active_days = (data.stats.days_active)
    total_characters = (data.stats.characters)
    abyss_total_stars = (data.abyss.previous.total_stars)
    resin_count = notes.current_resin
    resin_recovery_time = notes.remaining_resin_recovery_time
    await message.reply_text("Pranay Asia" + "\n" +
                             "uid : " + str(uid) + "\n" +
                             "-----------------------------------------------------------------" + "\n" +
                             "Resin Count: " + str(resin_count) + "/" + str(notes.max_resin) + "\n" +
                             "Countdown to next resin recovery: " + str(resin_recovery_time) + "\n" +
                             "Total No. of Active Days: " + str(active_days) + "\n" +
                             "Total No. of Characters: " + str(total_characters) + "\n" +
                             "Total Stars in Abyss: " + str(abyss_total_stars)
                             )


@bot.on_message(filters.command('redeemcode'))
def redeem_code(bot, message):
    message.reply_text("Send the Code to Redeem")


bot.run()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒时光 2025-02-09 05:48:47

尝试Message.Text

我将其用作用户机器人,但没有太大变化。该代码将已发送的消息保存到变量并过滤命令本身。对于机器人,它会更容易:答案= message.text

@app.on_message(filters.command("ns", prefixes=".") & filters.text)
async def EXAMPLE(_,msg):   
    orig_text = msg.text.split(".ns ", maxsplit=1)[1]
    text = orig_text

try message.text

I use it as a userbot but nothing changes so much. This piece of code saves the sent message to a variable and filters out the command itself. For a bot it will be easier: answer = message.text

@app.on_message(filters.command("ns", prefixes=".") & filters.text)
async def EXAMPLE(_,msg):   
    orig_text = msg.text.split(".ns ", maxsplit=1)[1]
    text = orig_text
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文