#!/usr/bin/env ruby

require 'discordrb'

token = ENV['DISCORD_BOT_TOKEN']

unless token
  puts "Error: DISCORD_BOT_TOKEN environment variable not set"
  exit 1
end

begin
  bot = Discordrb::Bot.new(token: token)
  app_id = bot.profile.id
  
  # Permissions needed:
  # - Send Messages (2048)
  # - Read Messages/View Channels (1024)
  # - Read Message History (65536)
  # - Add Reactions (64)
  # - Use Slash Commands (2147483648)
  permissions = 2048 + 1024 + 65536 + 64
  
  invite_url = "https://discord.com/api/oauth2/authorize?client_id=#{app_id}&permissions=#{permissions}&scope=bot"
  
  puts "Bot Invite URL:"
  puts invite_url
  puts "\nOpen this URL in your browser to add the bot to your server."
rescue => e
  puts "Error: #{e.message}"
  puts "Make sure your DISCORD_BOT_TOKEN is valid."
end