欢迎来到 Discord.py 教程系列,这里我们将深入探讨如何使用 Discord.py 库来创建和管理 Discord 机器人。本文档将为你提供 Discord.py 的基础知识,帮助你快速上手。

快速开始

  1. 安装 Discord.py
    首先,你需要安装 Discord.py 库。你可以通过以下命令来安装:

    pip install discord.py
    
  2. 创建你的第一个机器人
    创建一个简单的机器人,你需要先注册一个 Discord 应用,并获取 bot token

  3. 编写代码
    使用 Discord.py 库编写你的机器人代码,你可以参考以下示例:

    import discord
    
    client = discord.Client()
    
    @client.event
    async def on_ready():
        print(f'Logged in as {client.user}')
    
    @client.event
    async def on_message(message):
        if message.author == client.user:
            return
    
        if message.content.startswith('!hello'):
            await message.channel.send('Hello!')
    
    client.run('你的 bot token')
    

文档资源

为了更深入地了解 Discord.py,以下是一些推荐的文档资源:

图片示例

机器人代码运行示例

robot_running

机器人响应消息

bot_response_message

希望这份指南能帮助你开始使用 Discord.py 创建你的第一个机器人!如果你有任何问题,欢迎在 我们的论坛 上提问。