Discord.ButtonStyle Error

I have no idea why this isn’t working, I have all the required libraries, have copied the docs and followed a tutorial, but still it fails to work. I get this error:

Ignoring exception in command test:
Traceback (most recent call last):
  File "/home/runner/InterCity-Bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 17, in test
    button = discord_ui.Button(label="Click me!", style= discord.ButtonStyle.green)
AttributeError: module 'discord' has no attribute 'ButtonStyle'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/InterCity-Bot/venv/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/runner/InterCity-Bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/runner/InterCity-Bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord' has no attribute 'ButtonStyle'

This is my repl:
https://replit.com/@ProbablyIdiot/InterCity-Bot

Thanks in advance

try after running in Shell

poetry remove discord2
poetry add py-cord
1 Like

I get this error:
SolverProblemError

Because no versions of replit match >3.2.4,<3.2.5 || >3.2.5,<3.2.6 || >3.2.6,<3.2.7 || >3.2.7,<4.0.0
and replit (3.2.4) depends on typing_extensions (>=3.7.4,<4.0.0), replit (>=3.2.4,<3.2.5 || >3.2.5,<3.2.6 || >3.2.6,<3.2.7 || >3.2.7,<4.0.0) requires typing_extensions (>=3.7.4,<4.0.0).
And because replit (3.2.6) depends on typing_extensions (>=3.7.4,<4.0.0), replit (>=3.2.4,<3.2.5 || >3.2.5,<3.2.7 || >3.2.7,<4.0.0) requires typing_extensions (>=3.7.4,<4.0.0).
And because replit (3.2.7) depends on typing_extensions (>=3.7.4,<4.0.0)
and replit (3.2.5) depends on typing_extensions (>=3.7.4,<4.0.0), replit (>=3.2.4,<4.0.0) requires typing_extensions (>=3.7.4,<4.0.0).
Because no versions of py-cord match >2.4.1,<3.0.0
and py-cord (2.4.1) depends on typing-extensions (>=4,<5), py-cord (>=2.4.1,<3.0.0) requires typing-extensions (>=4,<5).
Thus, py-cord (>=2.4.1,<3.0.0) is incompatible with replit (>=3.2.4,<4.0.0).
So, because python-template depends on both replit (^3.2.4) and py-cord (^2.4.1), version solving failed.

at venv/lib/python3.10/site-packages/poetry/puzzle/solver.py:241 in _solve
237│ packages = result.packages
238│ except OverrideNeeded as e:
239│ return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
240│ except SolveFailure as e:
→ 241│ raise SolverProblemError(e)
242│
243│ results = dict(
244│ depth_first_search(
245│ PackageNode(self._package, packages), aggregate_package_nodes

It’s because you are using discord_ui instead of discord.ui. If you need to use discord_ui you can change that by replacing

import discord_ui

To

from discord import ui as discord_ui