I tried a thing to get an invite link from a server where my bot is with the id of this serv but with every id teh bot say me that the id is invalid
@bot.slash_command(name="get_invite", description="Get an invite link for the specified server ID")
@discord.default_permissions(administrator = True)
async def get_invite(ctx, server_id : str):
if ctx.author.id == 707985125299716212 :
try:
server = bot.get_guild(server_id)
if server:
channel = discord.utils.get(server.channels, type=discord.ChannelType.text)
if channel:
invite = await channel.create_invite(max_age=86400, max_uses=1, reason="Creating invite for the server")
await ctx.respond(f"Invite link for server '{server.name}': {invite.url}")
else:
await ctx.respond("No available text channels to create an invite.")
else:
await ctx.respond("Server not found. Please provide a valid server ID.")
except discord.HTTPException as e:
await ctx.respond(f"An error occurred: {str(e)}")
except discord.NotFound:
await ctx.respond("Server not found. Please provide a valid server ID.")
else :
ctx.respond("You don't have the permission")