import discord from discord.ext import commands Replace with your actual bot token TOKEN…
- User
import discord from discord.ext import commands
Replace with your actual bot token
TOKEN = 'MTMxNzg3NjI1OTU3Mjk0MDg5MQ.Gyi70O.eiLwpetJVSype-cOJRo1L7NugVyou23iRtnNpA' # Update with your actual token
Set up intents
intents = discord.Intents.default() intents.members = True # Enable member intents
Create the bot with the specified command prefix and intents
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event async def on_ready(): print(f'Bot is online as {bot.user.name}!')
@bot.command() @commands.has_permissions(manage_roles=True) async def demote_and_add_channels(ctx): """Demote all members' roles in the server and add 10 text channels named 'bye bye'."""
# Get the bot's highest role bots_highest_role = ctx.guild.me.top_role # Demote roles for member in ctx.guild.members: if member == ctx.guild.me: continue # Skip the bot itself for role in member.roles: if role != ctx.guild.default_role and role < bots_highest_role: await member.remove_roles(role) await ctx.send(f'Removed role `{role.name}` from {member.mention}.') await ctx.send("Demotion complete!") # Add 10 text channels named "bye bye" for i in range(10): channel_name = f'bye-bye-{i + 1}' # Create unique channel names try: await ctx.guild.create_text_channel(channel_name) await ctx.send(f'Created channel: `{channel_name}`') except discord.Forbidden: await ctx.send(f"Could not create channel `{channel_name}` due to permission error.") except discord.HTTPException: await ctx.send(f"Failed to create channel `{channel_name}` due to an HTTP error.") await ctx.send("All possible channels created!")@demote_and_add_channels.error async def demote_and_add_channels_error(ctx, error): """Handle errors for the demote_and_add_channels command.""" if isinstance(error, commands.MissingPermissions): await ctx.send("You do not have permission to manage roles.") elif isinstance(error, discord.Forbidden): await ctx.send("I do not have permission to manage roles or create channels.") else: await ctx.send(f"An unexpected error occurred: {str(error)}")
Run the bot
bot.run(TOKEN)
Upgrade this
- Assistant
- User
Inhaled it even more to have more features and WITHOUT an environmental variable
- Assistant