想要创建一个 Discord 机器人来帮助你管理服务器或者提供一些有趣的功能吗?这里是一个简单的 Discord Bot 教程,带你一步步完成。

安装 Discord API 库

首先,你需要安装一个 Discord API 库,比如 discord.py。你可以在命令行中运行以下命令来安装:

pip install discord.py

创建你的第一个 Bot

一旦安装了库,你可以开始创建你的第一个 Bot。以下是一个简单的例子:

import discord

intents = discord.Intents.default()
bot = discord.Bot(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.run('你的 token')

使用命令

在 Discord 服务器中,你可以使用 /ping 命令来测试你的 Bot 是否正常工作。

扩展阅读

想要了解更多关于 Discord Bot 的知识?可以阅读我们的 Discord Bot 高级教程

Discord Bot 示例