📌  相关文章
📜  如何在 discord.py 上获取作者 - Python (1)

📅  最后修改于: 2023-12-03 14:52:16.387000             🧑  作者: Mango

如何在 discord.py 上获取作者 - Python

在 discord.py 中,可以使用 discord.Clientdiscord.Bot 类来获取作者的信息。

使用 discord.Client

可以通过 discord.Client 类来获取当前 Discord 服务器上作者的信息。

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.typing = False
intents.presences = False

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    # 获取当前 Discord 服务器的作者
    guild = client.guilds[0]
    author = guild.owner

    print(f"The author's username is {author.name}")
    print(f"The author's ID is {author.id}")

client.run('YOUR_BOT_TOKEN')
使用 discord.Bot

如果你正在编写一个 Discord Bot,你可以使用 discord.Bot 类来获取作者的信息。

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.typing = False
intents.presences = False

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    # 获取当前 Discord 服务器的作者
    guild = bot.guilds[0]
    author = guild.owner

    print(f"The author's username is {author.name}")
    print(f"The author's ID is {author.id}")

bot.run('YOUR_BOT_TOKEN')

以上代码获取了 Discord 服务器中的作者信息,并在控制台打印了作者的用户名和 ID。

请确保将 YOUR_BOT_TOKEN 替换为你自己的 Discord Bot 的令牌。

希望这个介绍对你有所帮助!

返回的代码片段已按markdown标明。