我正在发现python discord机器人模块,练习我的python是一个很好的练习。所以使用 discord 模块我尝试创建一个频道并同时将其放入变量中(我不想在创建后在列表中搜索频道(
这是我尝试执行的代码:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "?")
@client.event
async def on_ready():
server = client.get_server(os.environ['DISCORD_SERVER_ID])
cCurrent = client.create_channel(server, str("%s 0" %(pokeName)))
[...]
await client.send_message(cCurrent, embed=raid.embed())
当我执行此代码时,出现错误:
in send_message
[...]
in _resolve_destination
raise InvalidArgument(fmt.format(destination))
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received generator
所以我想象client.create_channel
没有被执行,这使用 python 正常吗?
如何同时在客户端和变量中创建新的通道对象?
Client.create_channel
是一个协程,这意味着你必须使用await
语法(或 Python 3.4 中的yield from
(来获取其值:
cCurrent = await client.create_channel(server, str("%s 0" %(pokeName)))