<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Golang on Wayne X.Y. Blog</title>
    <link>/tags/golang/</link>
    <description>Recent content in Golang on Wayne X.Y. Blog</description>
    <generator>Hugo</generator>
    <language>zh-TW</language>
    <lastBuildDate>Wed, 11 Feb 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="/tags/golang/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>使用 Golang &#43; Google Gemini API 打造 Discord AI 聊天機器人</title>
      <link>/zh/2026/02/11/discord-chatbot-gemini/</link>
      <pubDate>Wed, 11 Feb 2026 00:00:00 +0000</pubDate>
      <guid>/zh/2026/02/11/discord-chatbot-gemini/</guid>
      <description>&lt;h1 id=&#34;使用-golang--google-gemini-api-打造-discord-ai-聊天機器人&#34;&gt;使用 Golang + Google Gemini API 打造 Discord AI 聊天機器人&lt;/h1&gt;&#xA;&lt;p&gt;本文將使用 &lt;strong&gt;Golang&lt;/strong&gt; 語言，搭配 &lt;strong&gt;Google Gemini API&lt;/strong&gt;，實作一個 Discord 聊天機器人。&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;-前置需求-prerequisites&#34;&gt;🛠️ 前置需求 (Prerequisites)&lt;/h2&gt;&#xA;&lt;p&gt;在開始之前，請確保你已經準備好以下開發環境與 API Key：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Golang 環境&lt;/strong&gt;: 安裝 Go 1.25 或更高版本。&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Discord Bot Token&lt;/strong&gt;:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;前往 &lt;a href=&#34;https://discord.com/developers/applications&#34;&gt;Discord Developer Portal&lt;/a&gt;。&lt;/li&gt;&#xA;&lt;li&gt;建立一個新的 Application，並新增一個 Bot。&lt;/li&gt;&#xA;&lt;li&gt;取得 Bot Token (請妥善保存，不要外洩)。&#xA;&#xA;  &lt;img src=&#34;https://static.wayne-xy.com/02-11-post/discord-chatbot-token.png&#34; alt=&#34;&#34;&gt;&#xA;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;開啟 &lt;code&gt;Message Content Intent&lt;/code&gt; 權限，這樣機器人才讀得到使用者的訊息內容。&#xA;&#xA;  &lt;img src=&#34;https://static.wayne-xy.com/02-11-post/discord-chatbot-message.png&#34; alt=&#34;&#34;&gt;&#xA;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;透過 OAuth2 將 bot 邀請到你的 Discord 伺服器。&#xA;&lt;ul&gt;&#xA;&lt;li&gt;選擇 scope&#xA;&#xA;  &lt;img src=&#34;https://static.wayne-xy.com/02-11-post/discord-chatbot-OAuth2-scope.png&#34; alt=&#34;&#34;&gt;&#xA;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;選擇 permission&#xA;&#xA;  &lt;img src=&#34;https://static.wayne-xy.com/02-11-post/discord-chatbot-OAuth2-permission.png&#34; alt=&#34;&#34;&gt;&#xA;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;產生 url 並邀請 bot&#xA;&#xA;  &lt;img src=&#34;https://static.wayne-xy.com/02-11-post/discord-chatbot-OAuth2-url.png&#34; alt=&#34;&#34;&gt;&#xA;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;⚠️ 注意：此時的 bot 應該為離線狀態&lt;/p&gt;&lt;/blockquote&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Google Gemini API Key&lt;/strong&gt;:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;前往 &lt;a href=&#34;https://aistudio.google.com/app/apikey&#34;&gt;Google AI Studio&lt;/a&gt;。&lt;/li&gt;&#xA;&lt;li&gt;建立一個新的 API Key。&#xA;&#xA;  &lt;img src=&#34;https://static.wayne-xy.com/02-11-post/google-ai-studio-api.png&#34; alt=&#34;&#34;&gt;&#xA;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;-專案初始化&#34;&gt;🚀 專案初始化&lt;/h2&gt;&#xA;&lt;p&gt;首先，建立一個新的專案資料夾並初始化 Go 模組：&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
