GPT Discord Bot 使用教程

GPT Discord Bot 使用教程

gpt-discord-botExample Discord bot written in Python that uses the completions API to have conversations with the `text-davinci-003` model, and the moderations API to filter the messages.项目地址:https://gitcode.com/gh_mirrors/gp/gpt-discord-bot

1. 项目的目录结构及介绍

gpt-discord-bot/
├── bot.py
├── config.yaml
├── requirements.txt
├── README.md
└── utils/
    └── helpers.py
  • bot.py: 项目的启动文件,包含了Discord bot的主要逻辑。
  • config.yaml: 项目的配置文件,用于设置API密钥和其他配置参数。
  • requirements.txt: 列出了项目依赖的Python包。
  • README.md: 项目的说明文档。
  • utils/helpers.py: 包含了一些辅助函数和工具。

2. 项目的启动文件介绍

bot.py 是项目的启动文件,主要负责初始化Discord bot并连接到Discord服务器。以下是 bot.py 的主要内容:

import discord
from discord.ext import commands
import yaml

# 读取配置文件
with open("config.yaml", "r") as f:
    config = yaml.safe_load(f)

# 初始化bot
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)

# 定义事件
@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')

# 定义命令
@bot.command()
async def ping(ctx):
    await ctx.send('Pong!')

# 运行bot
bot.run(config['discord_token'])
  • import 语句导入了必要的模块。
  • yaml.safe_load 读取配置文件。
  • commands.Bot 初始化bot对象。
  • on_ready 事件在bot成功连接到Discord服务器时触发。
  • ping 命令用于测试bot是否正常工作。
  • bot.run 启动bot。

3. 项目的配置文件介绍

config.yaml 是项目的配置文件,包含了API密钥和其他配置参数。以下是一个示例配置文件的内容:

discord_token: "YOUR_DISCORD_BOT_TOKEN"
openai_api_key: "YOUR_OPENAI_API_KEY"
  • discord_token: Discord bot的令牌,用于连接到Discord服务器。
  • openai_api_key: OpenAI API的密钥,用于访问GPT-3.5-turbo模型。

请确保将 YOUR_DISCORD_BOT_TOKENYOUR_OPENAI_API_KEY 替换为实际的令牌和密钥。

gpt-discord-botExample Discord bot written in Python that uses the completions API to have conversations with the `text-davinci-003` model, and the moderations API to filter the messages.项目地址:https://gitcode.com/gh_mirrors/gp/gpt-discord-bot

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宫俊潇Gresham

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值