#Python dm to channel ig

8 messages · Page 1 of 1 (latest)

deft olive
#

Well im trying to make a bot that send those questions to a channel in a server but for some reason im have issues with it.

import discord
from discord.ext import commands
from discord import Embed

intents = discord.Intents.default()
intents.message_content = True
intents.members = True

bot = commands.Bot(command_prefix="!", intents=intents)

TOKEN = os.getenv("DISCORD_TOKEN")
CHANNEL_ID = os.getenv("1288131886857846884")  

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')

@bot.command()
async def ban(ctx, user_id: int):
    if not ctx.author.guild_permissions.ban_members:
        await ctx.send("You do not have permission to ban members.")
        return

    user = await bot.fetch_user(user_id)
    if not user:
        await ctx.send("User not found.")
        return
    
    await ctx.author.send(f"Please provide a reason for banning {user.name}.")
    reason_msg = await bot.wait_for('message', check=lambda m: m.author == ctx.author)

    await ctx.author.send("Please provide evidence (image URL).")
    evidence_msg = await bot.wait_for('message', check=lambda m: m.author == ctx.author)

    embed = Embed(title="Ban Action", description=f"{user.name} ({user.id}) was banned", color=discord.Color.red())
    embed.add_field(name="Moderator", value=ctx.author.name, inline=True)
    embed.add_field(name="Reason", value=reason_msg.content, inline=False)
    embed.add_field(name="Action", value="Ban", inline=True)
    embed.add_field(name="Evidence", value=evidence_msg.content, inline=False)

  
    channel = bot.get_channel(int(CHANNEL_ID))  # Ensure this is an integer in get_channel()
    if channel:
        await channel.send(embed=embed)
    else:
        await ctx.send("The specified channel is not accessible.")
    
    await ctx.guild.ban(user, reason=reason_msg.content)

    await ctx.author.send(f"{user.name} has been banned for: {reason_msg.content}. Evidence: {evidence_msg.content}")

bot.run(TOKEN)
deft olive
#

Is this possible redeye

deft olive
#

@still carbon

still carbon
#

@deft olive Why'd you ping

deft olive
still carbon
#

"for some reason it doesn't work" -> bad question, give exact details like error messages, unexpected behaviour, etc.

The env var for the channel ID looks weird, that seems to be a value and not the name

still carbon
deft olive