telegraf.js i18n- typeError:无法阅读Wizardscene中未定义的属性(读取' t')

发布于 2025-02-04 03:05:56 字数 715 浏览 2 评论 0原文

一切都起作用,但是在场景的第二阶段,I18N不确定。 I18N和机器人的场景都已注册。

const createPostHere = new Scenes.WizardScene('createPostHere',
    async (ctx) => {
        ctx.wizard.state.post = {}
        await ctx.reply(await ctx.i18n.t('createPost.promptTitle')) << everything works
        ctx.wizard.next()
    },
    async (ctx) => {
        ctx.wizard.state.post.title = ctx.message.text
        await ctx.reply(await ctx.i18n.t('createPost.promptText')) << node crashes
        ctx.wizard.next()
    },

所有注册的一切

bot.use(stage.middleware());
bot.use(i18n.middleware())

我真的不知道问题在哪里

Everything works, but in the second stage of the scene, i18n is undefined. i18n is registered, as are the scenes in the bot.

const createPostHere = new Scenes.WizardScene('createPostHere',
    async (ctx) => {
        ctx.wizard.state.post = {}
        await ctx.reply(await ctx.i18n.t('createPost.promptTitle')) << everything works
        ctx.wizard.next()
    },
    async (ctx) => {
        ctx.wizard.state.post.title = ctx.message.text
        await ctx.reply(await ctx.i18n.t('createPost.promptText')) << node crashes
        ctx.wizard.next()
    },

Everything registered

bot.use(stage.middleware());
bot.use(i18n.middleware())

I really don`t know where is the problem

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

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

发布评论

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

评论(2

泛泛之交 2025-02-11 03:05:56
async (ctx) => {
   await ctx.replyWithHTML(
       ctx.i18n.t('create-text')
   )

   ctx.scene.state.i18n = ctx.i18n
   ctx.wizard.next()
},

async (ctx) => {
   const { i18n } = ctx.scene.state
   await ctx.replyWithHTML(i18n.t('create-details'))

   await ctx.scene.leave()
}
async (ctx) => {
   await ctx.replyWithHTML(
       ctx.i18n.t('create-text')
   )

   ctx.scene.state.i18n = ctx.i18n
   ctx.wizard.next()
},

async (ctx) => {
   const { i18n } = ctx.scene.state
   await ctx.replyWithHTML(i18n.t('create-details'))

   await ctx.scene.leave()
}
刘备忘录 2025-02-11 03:05:56

您应该在舞台中间件之前先使用I18N。像这样:

bot.use(i18n.middleware());
bot.use(stage.middleware());

You should use i18n first before stage middleware. Like this:

bot.use(i18n.middleware());
bot.use(stage.middleware());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文