【问题标题】:Create Server using Discord Bot使用 Discord Bot 创建服务器
【发布时间】:2020-01-27 23:52:54
【问题描述】:

如果我们查看 discord 开发文档中的 Guild Create 事件,我们会看到以下内容:

我对此有几个问题。首先,我不确定何时可以使用机器人帐户创建服务器。在“用户最初连接时”部分之后,我尝试将服务器创建放入 on_ready 函数中,如下所示:

import discord
import asyncio

import bot.client.getkey as _getkey
from bot.utils import get_owner

class ImABot(discord.Client):
    async def on_ready(self):
        ts = await self.create_server("test")
        inv = await self.create_invite(ts.default_channel)
        await self.send_message(get_owner()) #get owner simply gets the user who owns the bot, me.
Bot = ImABot()


Bot.run(_getkey.key())

但是,我收到以下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "/Users/edl/Desktop/ /Programming/Github/Democracy-Bot/demobot/client/client.py", line 22, in on_ready
    inv = await self.create_invite(ts.default_channel)
  File "/usr/local/lib/python3.6/site-packages/discord/client.py", line 2628, in create_invite
    data = yield from self.http.create_invite(destination.id, **options)
AttributeError: 'NoneType' object has no attribute 'id'

我认为这意味着服务器没有创建。我希望有人可以给我关于创建服务器何时可以工作的信息,以及它是否可能首先。谢谢!

【问题讨论】:

标签: python python-3.x bots discord discord.py


【解决方案1】:

公会不再有默认频道,因此最好避免使用它们。

要获得第一个为服务器创建的频道,最好的办法是使用

discord.utils.get(new_server.channels, type=discord.ChannelType.text)

或者如果你使用discord.py重写,那么

new_server.text_channels[0]

然后您可以从该频道创建邀请。

【讨论】:

    【解决方案2】:

    Discord 机器人无法创建服务器;只有用户帐户可以。虽然可以创建一个帐户并使用其令牌制作一个自我机器人,但不推荐使用它,因为它是against the discord Tos

    【讨论】:

    • Client.create_guild 的文档另有说明:“不允许超过 10 个公会的机器人帐户创建公会。”因此,大概 10 个或更少的公会中的机器人帐户可能会创建一个公会
    猜你喜欢
    • 2021-01-12
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2021-10-21
    • 1970-01-01
    相关资源
    最近更新 更多