Skip to content

pgDora56/ConsoNance

Repository files navigation

ConsoNance

Consonance <-> Discord

Audio Stream Bot for Discord

Overview

Discord のボイスチャンネルにシステム音声(ループバック)をストリーミングする Bot。

2026年3月1日より Discord が全ボイス接続に DAVE (E2EE/MLS) プロトコルを強制したため、 v26.03.0 以降は disgoorg/disgo v0.19.2 + libdave.dll を使用する。

Prerequisites

  • Go 1.24 以上
  • CGO 有効な環境
  • C コンパイラ (MinGW64 GCC)
  • pkg-config (pkgconfiglite)
  • libdave v1.1.1 (Discord DAVE/E2EE プロトコル対応 — 下記参照)

Building

Windows

1. MSYS2 のインストール

  1. https://www.msys2.org/ からインストーラをダウンロードして実行(C:\msys64 にインストール)
  2. "MSYS2 MSYS" を開き、アップデートを実施:
    pacman -Syu
    pacman -Su
  3. MinGW64 の GCC をインストール:
    pacman -S mingw-w64-x86_64-gcc

2. pkg-config のインストール

管理者権限の PowerShell で:

choco install pkgconfiglite -y

3. libdave のインストール

PowerShell で:

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/disgoorg/godave/master/scripts/libdave_install.ps1" `
    -OutFile "$env:TEMP\libdave_install.ps1"
& "$env:TEMP\libdave_install.ps1" -Version "v1.1.1"

インストール後、新しい PowerShell を開き直すか以下を実行してパスを反映:

$env:PKG_CONFIG_PATH = [System.Environment]::GetEnvironmentVariable("PKG_CONFIG_PATH", "User")
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";" + $env:PATH

4. ビルド

付属の PowerShell スクリプトを使うのが最も簡単:

.\build-win.ps1

または make:

make build-win

手動で実行する場合:

$env:PKG_CONFIG_PATH = [System.Environment]::GetEnvironmentVariable("PKG_CONFIG_PATH", "User")
$env:PATH = "C:\msys64\mingw64\bin;" + [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";" + $env:PATH
$env:CGO_ENABLED = "1"
go build -o ConsoNance.exe .
Copy-Item "$env:LOCALAPPDATA\libdave\bin\libdave.dll" "libdave.dll" -Force

重要: Windows クロス CRT ヒープ問題への対処

libdave.dll は MSVC でコンパイルされているため、MinGW GCC の free() で解放しようとするとヒープ破壊が発生する。 この問題は github.com/disgoorg/godave/libdave@v0.1.0utils.go に存在し、 C.free()C.daveFree() に置き換えることで修正される。

ビルド前に以下で修正を適用する(make fix-libdave でも実行可能):

.\fix-libdave.ps1

Linux

Ensure you have gcc and opus library installed:

sudo apt-get install gcc libopus-dev  # For Debian/Ubuntu
# or
sudo yum install gcc opus-devel       # For CentOS/RHEL

Then build:

go build -o consonance

Or using Makefile:

make build-linux

macOS

Install opus library using Homebrew:

brew install opus

Then build:

go build -o consonance

Or using Makefile:

make build-mac

Configuration

Easy First-Time Setup

No manual configuration required! Just run the bot:

./consonance.exe  # or ./consonance on Linux/macOS

On first run, the bot will:

  1. Automatically create config.yaml if it doesn't exist
  2. Prompt you to enter your Discord bot token
  3. Save your token to config.yaml
  4. Prompt you to select an audio device
  5. Optionally save the device as default

Example first run:

=== Discord Bot Token Required ===
Your Discord bot token is not configured.

To get your bot token:
1. Go to https://discord.com/developers/applications
2. Select your application (or create a new one)
3. Navigate to the 'Bot' section
4. Click 'Reset Token' or 'Copy' to get your token
5. Make sure to enable 'MESSAGE CONTENT INTENT' under Privileged Gateway Intents

Paste your Discord bot token here: [YOUR_TOKEN]
✓ Discord token saved to config.yaml

=== Select Audio Device ===
Available audio devices for loopback capture:

[1] Speakers (Realtek High Definition Audio) (Default)
[2] Line (Yamaha SYNCROOM Driver)

Enter device number: 2
✓ Selected: Line (Yamaha SYNCROOM Driver)

Save this device as default in config.yaml? (y/n): y
✓ Device saved to config.yaml

Manual Configuration (Optional)

If you prefer to manually configure, copy config.yaml.example to config.yaml:

cp config.yaml.example config.yaml

Minimum required configuration:

discord_token: "YOUR_BOT_TOKEN_HERE"

Optional Auto-Connect Settings

To automatically join a voice channel on startup:

discord_token: "YOUR_BOT_TOKEN_HERE"
guild_id: "0987654321"    # Your Discord server (guild) ID
channel_id: "1234567890"  # Voice channel to auto-join

Getting Your Discord Bot Token

  1. Go to Discord Developer Portal
  2. Create a new application or select an existing one
  3. Navigate to the "Bot" section
  4. Click "Reset Token" and copy your bot token

Important: Enable Privileged Gateway Intents

⚠️ This step is required or you'll get authentication errors!

  1. In the Discord Developer Portal, go to your application
  2. Navigate to the "Bot" section
  3. Scroll down to "Privileged Gateway Intents"
  4. Enable the following intents:
    • MESSAGE CONTENT INTENT (required for commands)
    • SERVER MEMBERS INTENT (recommended)
    • PRESENCE INTENT (recommended)
  5. Click "Save Changes"

Without these intents enabled, you'll see an error like:

websocket: close 4004: Authentication failed.

Audio Device Selection

The bot supports two ways to select an audio device:

  1. Interactive Selection (Recommended): Leave audio_device_name empty or commented out in config.yaml. When you start the bot:

    • You'll see a numbered list of available devices
    • Enter the device number to select it
    • Optionally save your selection to config.yaml for future use
    === Select Audio Device ===
    Available audio devices for loopback capture:
    
    [1] Speakers (Realtek High Definition Audio) (Default)
    [2] Line (Yamaha SYNCROOM Driver)
    [3] Headphones (USB Audio)
    
    Enter device number: 2
    ✓ Selected: Line (Yamaha SYNCROOM Driver)
    
    Save this device as default in config.yaml? (y/n): y
    ✓ Device saved to config.yaml
    
  2. Pre-configured Device: Set audio_device_name in config.yaml to use a specific device automatically:

    audio_device_name: "Line (Yamaha SYNCROOM Driver)"

Usage

Starting the Bot

Simply run the executable:

./consonance.exe  # on Windows
./consonance      # on Linux/macOS

First-time users: The bot will guide you through:

  1. Creating config.yaml (if it doesn't exist)
  2. Entering your Discord bot token
  3. Selecting an audio device

Subsequent runs: The bot will use your saved configuration and start immediately.

The bot will connect to Discord. You can then:

  • Use Discord chat commands to join/leave voice channels (see below)
  • Or, if guild_id and channel_id are set in config.yaml, it will auto-join that channel

Discord Commands

You can control the bot by mentioning it in any text channel on your Discord server.

No configuration required! Just mention the bot with commands:

Join a Voice Channel

@YourBot join #channel-name

Or search by channel name (without #):

@YourBot join channel-name

Leave Voice Channel

@YourBot leave

Check Status

@YourBot status

Shows current connection status and streaming information.

Help

@YourBot help

Shows available commands.

How It Works

  • The bot captures system audio (loopback) from your computer
  • It encodes the audio to Opus format
  • The audio is streamed to the Discord voice channel in real-time
  • You can switch channels on-the-fly using Discord commands without restarting the bot

Notes

  • Make sure your Discord bot has the necessary permissions to join voice channels
  • Required bot permissions: Connect, Speak, Read Messages, Send Messages
  • The bot uses loopback audio capture to stream system audio

Development

Version Management

ConsoNance uses a simple version management system with the format YY.MM.minor (e.g., 26.03.0):

  • YY: Year (2-digit)
  • MM: Month (2-digit)
  • minor: Minor version number within the month

To update the version:

  1. Edit the Version constant in version.go:

    const Version = "26.03.0"  // Update this value
  2. The version will be displayed:

    • On application startup (in logs and console)
    • In the @Bot help command response

Build Targets (Makefile)

コマンド 説明
make build-win Windows 向けビルド + libdave.dll コピー
make fix-libdave libdave クロス CRT ヒープ修正を適用
make dist 配布用 zip を生成 (exe + dll + ライセンス)
make clean ビルド成果物を削除

Distribution

配布に必要なファイル:

ファイル 説明
ConsoNance.exe 本体
libdave.dll Discord DAVE 暗号化ライブラリ (MIT License)
LICENSE ConsoNance の GPL v3 ライセンス
NOTICE サードパーティライセンス表示

make distConsoNance-vXX.XX.X-windows-x64.zip が自動生成される。

Key Dependencies

ライブラリ 用途 リンク方式
disgoorg/disgo v0.19.2 Discord API (DAVE 対応) 静的
discord/libdave v1.1.1 DAVE E2EE 暗号化 動的 (DLL)
gen2brain/malgo オーディオキャプチャ 静的
layeh.com/gopus Opus エンコード 静的

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

What does GPL v3.0 mean?

  • ✅ You can use this software freely
  • ✅ You can modify the source code
  • ✅ You can distribute modified versions
  • ⚠️ Any derivative work must also be licensed under GPL v3.0
  • ⚠️ You must disclose the source code of derivative works
  • ⚠️ You must include the original copyright and license notices

Copyright (C) 2025 Kazuki F.

About

Audio Stream Bot for Discord

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors