python - I continue to get errors regarding ParseMode when trying to start my telegram bot - Stack Overflow

admin2025-04-17  3

This is the error I get every time I try to start the bot.

(venv) C:\Users\Due Bighelloni\Desktop\bingo bot>python versolarmoniabingobot.py Traceback (most recent call last):
   File "C:\Users\Due Bighelloni\Desktop\bingo bot\versolarmoniabingobot.py", line 2, in <module>
     from telegram.parsemode import parse_mode ModuleNotFoundError: No module named 'telegram.parsemode

This is what I get when I try to start the command python file.py

I tried to install and uninstall everything I could find here and in other forums. I checked the versions and still don't know the problem.

My code:

# MY PROBLEMS ARE HERE, IT'S ALL ABOUT THIS FIRST BLOCK.

from telegram import Update, ParseMode
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
import random
import time

# THE CODE GOES ON LIKE THIS...

# Sostituisci con il tuo token
TOKEN = '123456789:IFAGHSAIUSHIUAHDIUFHAS' """EXAMPLE"""

# Lista dei numeri del bingo
numbers = [str(i) for i in range(1, 90)]  # Numeri da 1 a 90

# Variabili di stato del gioco
game_active = False
current_numbers = []
players = {}
victories = {}
admin_ids = [472836500]  # Lista degli ID Telegram degli admin (devi inserire qui i tuoi ID)

# Funzione per ottenere i numeri del giocatore
def get_player_numbers() -> dict:
    """Genera numeri casuali per ogni giocatore"""
    player_numbers = {}
    for player_id in players:
        player_numbers[player_id] = random.sample(numbers, 5*5)  # Ogni giocatore ha 25 numeri da fare corrispondere
    return player_numbers

# Funzione di start
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Messaggio iniziale del bot"""
    await update.message.reply_text(
        "Benvenuto all'Armonia Bingo! Solo il proprietario del gruppo può avviare una nuova partita con il comando /gioca.\n"
        "Puoi anche usare /help per sapere come giocare.",
        parse_mode=ParseMode.MARKDOWN
    )

# Funzione di aiuto
async def help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Messaggio di aiuto"""
    await update.message.reply_text(
        "Per giocare a Bingo, usa il comando /gioca per iniziare una partita.\n"
        "Dopo aver iniziato, il bot chiamerà i numeri, e tu dovrai segnare quelli che hai!",
        parse_mode=ParseMode.MARKDOWN
    )

# Funzione per avviare il gioco (solo admin)
async def play_bingo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Avvia il gioco del Bingo"""
    global game_active, current_numbers, players
    user_id = update.message.from_user.id

   

This is the error I get every time I try to start the bot.

(venv) C:\Users\Due Bighelloni\Desktop\bingo bot>python versolarmoniabingobot.py Traceback (most recent call last):
   File "C:\Users\Due Bighelloni\Desktop\bingo bot\versolarmoniabingobot.py", line 2, in <module>
     from telegram.parsemode import parse_mode ModuleNotFoundError: No module named 'telegram.parsemode

This is what I get when I try to start the command python file.py

I tried to install and uninstall everything I could find here and in other forums. I checked the versions and still don't know the problem.

My code:

# MY PROBLEMS ARE HERE, IT'S ALL ABOUT THIS FIRST BLOCK.

from telegram import Update, ParseMode
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
import random
import time

# THE CODE GOES ON LIKE THIS...

# Sostituisci con il tuo token
TOKEN = '123456789:IFAGHSAIUSHIUAHDIUFHAS' """EXAMPLE"""

# Lista dei numeri del bingo
numbers = [str(i) for i in range(1, 90)]  # Numeri da 1 a 90

# Variabili di stato del gioco
game_active = False
current_numbers = []
players = {}
victories = {}
admin_ids = [472836500]  # Lista degli ID Telegram degli admin (devi inserire qui i tuoi ID)

# Funzione per ottenere i numeri del giocatore
def get_player_numbers() -> dict:
    """Genera numeri casuali per ogni giocatore"""
    player_numbers = {}
    for player_id in players:
        player_numbers[player_id] = random.sample(numbers, 5*5)  # Ogni giocatore ha 25 numeri da fare corrispondere
    return player_numbers

# Funzione di start
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Messaggio iniziale del bot"""
    await update.message.reply_text(
        "Benvenuto all'Armonia Bingo! Solo il proprietario del gruppo può avviare una nuova partita con il comando /gioca.\n"
        "Puoi anche usare /help per sapere come giocare.",
        parse_mode=ParseMode.MARKDOWN
    )

# Funzione di aiuto
async def help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Messaggio di aiuto"""
    await update.message.reply_text(
        "Per giocare a Bingo, usa il comando /gioca per iniziare una partita.\n"
        "Dopo aver iniziato, il bot chiamerà i numeri, e tu dovrai segnare quelli che hai!",
        parse_mode=ParseMode.MARKDOWN
    )

# Funzione per avviare il gioco (solo admin)
async def play_bingo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    """Avvia il gioco del Bingo"""
    global game_active, current_numbers, players
    user_id = update.message.from_user.id

   
Share Improve this question edited Feb 5 at 2:58 President James K. Polk 42.1k30 gold badges109 silver badges145 bronze badges asked Jan 30 at 20:00 DanielDaniel 1
Add a comment  | 

1 Answer 1

Reset to default 0

Since version 20+ of python-telegram-bot, ParseMode has been moved to telegram.constants PTB Doc link

class telegram.constants.ParseMode(value, names=, *values, module=None, qualname=None, type=None, start=1, boundary=None)

try this

from telegram.constants import ParseMode

so your code will be like

from telegram import Update
from telegram.constants import ParseMode
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
import random
import time

转载请注明原文地址:http://anycun.com/QandA/1744892858a89111.html