Skip to content

Instantly share code, notes, and snippets.

@dougalcorn
Last active March 18, 2025 17:52
Show Gist options
  • Save dougalcorn/15f58ee123b83aa212fe6c295277d3a8 to your computer and use it in GitHub Desktop.
Save dougalcorn/15f58ee123b83aa212fe6c295277d3a8 to your computer and use it in GitHub Desktop.
problem with nostrum consumer
defmodule MyApp.Application do
@moduledoc false
use Application
require Logger
@impl true
def start(_type, _args) do
Logger.info("Starting MyApp application...")
children = [
MyApp.StaticStore,
MyApp.Repo,
MyApp.Consumer,
MyApp.Commands.Registry
]
Logger.info("Starting with #{length(children)} children")
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
defmodule MyApp.Consumer do
@moduledoc """
Discord event consumer for the bot.
"""
use Nostrum.Consumer
require Logger
alias Nostrum.Cache.Me
# We'll use a process dictionary entry to store the current user
# This avoids overriding Nostrum's init function
def handle_event({:READY, _data, _ws_state}) do
Logger.info("Bot is ready!")
case Me.get() do
nil ->
Logger.error("Failed to get current user: nil returned")
:ok
current_user ->
Logger.info("Logged in as: #{current_user.username}")
:ok
end
end
end
import Config
# Set Nostrum configuration directly here
config :nostrum,
token: System.get_env("DISCORD_BOT_TOKEN"),
gateway_intents: [:direct_messages, :guild_messages, :message_content, :guilds],
youtubedl: false, # Disable youtube-dl warning
streamlink: false, # Disable streamlink warning
ffmpeg: false # Disable ffmpeg warning
# Optional runtime configuration that can override values from other config files
if config_env() == :prod do
# Any runtime-specific production configuration can go here
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment