'Module 'discord' has no attribute 'ui'
I have a problem with my code from my discord bot. When I run the program I get an error message, but I have all imports up to date. Can someone help me please, because I really have no idea how to fix this . If you have any more questions just write in.
Here is the error:
AttributeError: module 'discord' has no attribute 'ui'
And Here is my Code:
import discord
from discord.ext import commands
from discord_ui import ButtonInteraction, Button, ButtonStyle, UI
intent = discord.Intents.default()
intent.members = True
bot = commands.Bot(command_prefix="!", intent=intent)
role_id = 938465872098512956
guild_id = 938215477157703771
class RoleButton(discord.ui.Button):
def __init__(self):
super().__init__(
label="Verifiziere dich hier!",
style=discord.enums.ButtonStyle.blurple,
custom_id="interaction:RoleButton",
)
async def callback(self, interaction: discord.Interaction):
user = interaction.user
role = interaction.guild.get_role(role_id)
if role is None:
return
if role not in user.roles:
await user.add_roles(role)
await interaction.response.send_message(f"🎉 Du bist nun verifiziert!", ephemeral=True)
else:
await interaction.response.send_message(f"❌ Du bist bereits verifiziert!", ephemeral=True)
BILD_URL = ""
BESCHREIBUNG = "Test"
@bot.command()
async def post(ctx: commands.Context): # Command
view = discord.ui.View(timeout=None)
view.add_item(RoleButton())
await ctx.send(f"{BILD_URL}")
await ctx.send(f"{BESCHREIBUNG}", view=view)
@bot.event
async def on_ready():
print("ONLINE!")
view = discord.ui.View(timeout=None)
view.add_item(RoleButton())
bot.add_view(view)
bot.run("")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
