DiscordPy, 未定义的变量通道

问题描述 投票:0回答:1

我在使用 discord.py 时遇到了一些问题,我想用 discord.py 发送 jpeg 文件,但它给了我错误。

消息": "未定义变量'channel'

 import discord

 if message.content.startswith('!hello'):
    await channel.send('Hello', file=discord.File('fff1.jpeg', spoiler=False))
python discord.py discord.py-rewrite
1个回答
0
投票

你没有定义 channel。因此,Python 不知道你想把消息发送到哪里。如果你已经有了消息,你可以使用 message.channel 代替 channel.在它来自的同一个通道中发送它。

另外,如果您只是在使用命令,您可能会发现尝试使用 命令类 从discord.ext.来的。

© www.soinside.com 2019 - 2024. All rights reserved.