使用python在discord中创建频道

时间:2018-04-10 15:25:44

标签: python bots discord discord.py

我开始使用python制作一个discord bot。我想创建一个文本频道,但是我遇到了一些错误。

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)

1 个答案:

答案 0 :(得分:0)

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

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

client.create_channel(server, ...)

正如您给出的代码所暗示的那样 这里的错误是客户端<discord.ext.commands.bot.Bot>没有server属性。