亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么它說 USER_SETUP 是未使用的變量,而實際上它不是?不和諧.PY

為什么它說 USER_SETUP 是未使用的變量,而實際上它不是?不和諧.PY

守著星空守著你 2023-08-22 16:50:09
您好,我正在嘗試制作一個反應角色機器人,但遇到了這個錯誤。它說我的名為 USER_SETUP 的變量未使用,但事實并非如此。我已經嘗試了大多數事情,但我似乎無法做到正確。這是我的代碼:USER_DOING_SETUP = FalseUSER_SETUP = [email protected](aliases=['rr', 'reactionroles'])async def reactionrole(ctx, user, arg):    if arg == "setup":        if USER_DOING_SETUP == False:            userId = user.id            USER_SETUP = userId            USER_DOING_SETUP = True            await ctx.send(f"TEST REACTION ROLES TYPE {BOT_PREFIX}!rr cancel TO CANCEL")        else:            await ctx.send("Setup is used by another user")    elif arg == "cancel":        USER_DOING_SETUP = True        USER_SETUP = 0        await ctx.send("setup was cancled :)")@client.eventasync def on_message(message):    if message.author != client.user:        if USER_DOING_SETUP == False:            await message.channel.send("false")        elif USER_DOING_SETUP == True:            if USER_SETUP == message.author.id:                await message.channel.send("true")            else:                await message.channel.send("false")錯誤: Unused variable 'USER_SETUP'
查看完整描述

1 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

您必須在使用它們的每個函數的開頭聲明您正在使用每個全局變量(或者至少在讀取/分配給它們之前):


USER_DOING_SETUP = False

USER_SETUP = 0


@client.command(aliases=['rr', 'reactionroles'])

async def reactionrole(ctx, user, arg):

    global USER_DOING_SETUP

    global USER_SETUP

    if arg == "setup":

        if USER_DOING_SETUP == False:

            userId = user.id

            USER_SETUP = userId

            USER_DOING_SETUP = True

            await ctx.send(f"TEST REACTION ROLES TYPE {BOT_PREFIX}!rr cancel TO CANCEL")

        else:

            await ctx.send("Setup is used by another user")

    elif arg == "cancel":

        USER_DOING_SETUP = True

        USER_SETUP = 0

        await ctx.send("setup was cancled :)")


@client.event

async def on_message(message):

    global USER_DOING_SETUP

    global USER_SETUP

    if message.author != client.user:

        if USER_DOING_SETUP == False:

            await message.channel.send("false")

        elif USER_DOING_SETUP == True:

            if USER_SETUP == message.author.id:

                await message.channel.send("true")

            else:

                await message.channel.send("false")


查看完整回答
反對 回復 2023-08-22
  • 1 回答
  • 0 關注
  • 1331 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號