Latest posts on Бот discord на python с выдачей ролей по нажатию на кнопку topichttps://python.su/forum/topic/41690/2022-06-19T17:05:50+03:00Общий :: Python для экспертов :: Бот discord на python с выдачей ролей по нажатию на кнопку
2022-06-19T17:05:50+03:00Nindziaorel222619Подскажите, где ошибка?<br/>
Общий :: Python для экспертов :: Бот discord на python с выдачей ролей по нажатию на кнопку
2022-06-19T17:05:24+03:00Nindziaorel222618Помогите пожалуйста с ботом. Код взял с зарубежных уроков. Там все у них работает, а у меня нет(<br/>import discord<br/>from discord import app_commands<br/><br/>class button_view(discord.ui.View):<br/>def __init__(self) -> None:<br/>super().__init__(timeout = None)<br/><br/>@discord.ui.button(label = “verify”, style = discord.ButtonStyle.green, custom_id = “verify”)<br/>async def verify(self, interaction: discord.Interaction, button: discord.ui.Button):<br/>if type(client.role) is not discord.Role:<br/>client.role = interaction.guild.get_role(980107923646722068)<br/>if client.role not in interaction.user.roles:<br/>await interaction.user.add_roles(client.role)<br/>await interaction.response.send_message(f“I have given you {client.role.mention}!”, ephemeral = True)<br/>else: await interaction.response.send_message(f“You already have {client.role.metion}!”, ephemeral = True)<br/><br/>class aclient(discord.Client):<br/>def __init__(self):<br/>super().__init__(intents = discord.Intents.default())<br/>self.synced = False<br/>self.role = 980107923646722068<br/>self.added = False<br/><br/>async def on_ready(self):<br/>await self.wait_until_ready()<br/>if not self.synced:<br/>#<br/>self.synced = True<br/>if not self.added:<br/>self.add_view(button_view())<br/>self.added = True<br/>print(f“We have logged in as {self.user}.”)<br/><br/>client = aclient()<br/>tree = app_commands.CommandTree(client)<br/><br/>@tree.command(guild = discord.Object(id=979417086570930186), name = ‘button’, description='Launches role button')<br/>async def button(interaction: discord.Interaction):<br/>await interaction.response.send_message(view = button_view())<br/><br/>client.run('my token')<br/><br/>Ошибка вылазит такая:<br/><br/>Traceback (most recent call last):<br/>File “C:\Work\Python\Python Test1\Bot roles эксперементальный\roli — копия.py”, line 1, in <module><br/>from discord import app_commands<br/>File “C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\__init__.py”, line 12, in <module><br/>from .commands import *<br/>File “C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\commands.py”, line 51, in <module><br/>from ..enums import AppCommandOptionType, AppCommandType<br/>ImportError: cannot import name ‘AppCommandOptionType’ from ‘discord.enums’ (C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\enums.py)<br/><br/>Process finished with exit code 1<br/><br/><br/>Хотя установленные все модули последних версий discord 2+ и т.д.