Проблема с дискорд ботом для цуефа

Рейтинг: 1Ответов: 1Опубликовано: 14.05.2023
import discord  #Подключаем библиотеку
import random
from discord.ext import commands
from discord import Member
intents = discord.Intents.default() #Подключаем "Разрешения"
intents.message_content = True

bot = commands.Bot(command_prefix='/', intents=intents) 

#С помощью декоратора создаём первую команду
@bot.command()
async def ping(ctx):
    await ctx.send('pong')



@bot.command() 
async def knb(ctx, choice: str): 
    choices = ['rock', 'paper', 'scissors'] 
    # проверяем, что выбор пользователя является допустимым 
    if choice not in choices: 
        await ctx.send(f'Выберите: {", ".join(choices)}') 
        return 
    bot_choice = random.choice(choices) 
    # определяем победителя и отправляем результат в чат 
    if choice == 'rock' and bot_choice == 'scissors'\
            or choice == 'paper' and bot_choice == 'rock' \
            or choice == 'scissors' and bot_choice == 'paper': \
        await ctx.send(f'{ctx.author.mention} победил! Бот выбрал {bot_choice}.') 
    elif choice == bot_choice: 
        await ctx.send(f'{ctx.author.mention} ничья! Бот выбрал {bot_choice}.') 
    else: 
        await ctx.send(f'{ctx.author.mention} проиграл! Бот выбрал {bot_choice}.') 

Ответы

▲ 0

У меня всё работает. Прописываю /knb (rock paper или scissors) если что.

import discord  #Подключаем библиотеку
import random
from discord.ext import commands
from discord import Member
intents = discord.Intents.default() #Подключаем "Разрешения"
intents.message_content = True

bot = commands.Bot(command_prefix='/', intents=intents) 

#С помощью декоратора создаём первую команду
@bot.command()
async def ping(ctx):
    await ctx.send('pong')



@bot.command() 
async def knb(ctx, choice: str): 
    choices = ['rock', 'paper', 'scissors'] 
    # проверяем, что выбор пользователя является допустимым 
    if choice not in choices: 
        await ctx.send(f'Выберите: {", ".join(choices)}') 
        return 
    bot_choice = random.choice(choices) 
    # определяем победителя и отправляем результат в чат 
    if choice == 'rock' and bot_choice == 'scissors'\
            or choice == 'paper' and bot_choice == 'rock' \
            or choice == 'scissors' and bot_choice == 'paper': \
        await ctx.send(f'{ctx.author.mention} победил! Бот выбрал {bot_choice}.') 
    elif choice == bot_choice: 
        await ctx.send(f'{ctx.author.mention} ничья! Бот выбрал {bot_choice}.') 
    else: 
        await ctx.send(f'{ctx.author.mention} проиграл! Бот выбрал {bot_choice}.')
bot.run("TOKEN")