【问题标题】:Creating channel in discord using python使用 python 在不和谐中创建频道
【发布时间】:2018-04-11 01:32:10
【问题描述】:

我开始使用 python 制作一个不和谐的机器人。我想创建一个文本频道,但出现了一些错误。

File "C:\Users\playe\Anaconda3\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "E:\Programming\Python\Discord Bots\DC Black Jack Bot\dc_blackjack_bot.py", line 17, in blackjack
    await client.create_channel(client.server, 'This channel is created by ', type=discord.ChannelType.text)
  File "C:\Users\playe\Anaconda3\lib\site-packages\discord\client.py", line 296, in __getattr__
    raise AttributeError(msg.format(self.__class__, name))
AttributeError: '<class 'discord.ext.commands.bot.Bot'>' object has no attribute 'server'

这是我的代码:

server = context.message.server
await client.create_channel(
    server, 
    'This channel is created by ' + context.message.author.name,
    type=discord.ChannelType.text)

【问题讨论】:

  • 您使用的是异步版本还是重写版本的 discord.py? client 是什么? context 是什么?你在使用 ext.commands 吗?
  • 是的,我正在使用异步。这是完整的功能: async def newserver(context): server = context.message.server await client.create_channel(server, '这个频道是由 ' + context.message.author.name, type=discord.ChannelType.text 创建的) 客户是我的机器人
  • 您在此处发布的错误已在您添加的代码中得到修复。你现在遇到什么错误?
  • 还是一样。
  • 文件“C:\Users\playe\Anaconda3\lib\site-packages\discord\ext\commands\core.py”,第 50 行,包装 ret = yield from coro(*args, **kwargs) 文件“E:\Programming\Python\Discord Bots\DC Black Jack Bot\dc_blackjack_bot.py”,第 16 行,在 newserver 中等待 client.create_channel(server, '此频道由 ' + context.message 创建。 author.name, type=discord.ChannelType.text)

标签: python bots discord discord.py


【解决方案1】:

您的问题是印刷问题。您的代码与回溯不匹配,实际上按预期工作。回溯意味着您的代码包含

client.create_channel(client.server, ...)

不是

client.create_channel(server, ...)

正如您给定的代码所建议的那样。
这里的错误是那个客户端,它是一个&lt;discord.ext.commands.bot.Bot&gt; 没有server 属性。

【讨论】:

    猜你喜欢
    • 2021-11-23
    • 2019-08-22
    • 2021-10-25
    • 2020-09-06
    • 2020-11-07
    • 2020-12-28
    • 2021-01-31
    • 2022-01-24
    • 2021-09-15
    相关资源
    最近更新 更多