NameError: name 'guild' 未定义。问题是什么?

时间:2021-01-11 19:10:37

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

mC = guild.member_count
channel = client.get_channel(798156048571948463)
await channel.edit(name = f"Member count: {mC}")

问题出在“mC”上,但为什么呢?

2 个答案:

答案 0 :(得分:4)

在第一行中,您使用了 def update(i, fig, ax): while i <= 50: circle_white = plt.Circle((0.5, 0.5), i/100, color='white') ax.add_artist(circle_white) return [circle_white] while 50 < i <= 100: circle_red1 = plt.Circle((1, 1), i/1000, color='red') circle_red2 = plt.Circle((0, 0), i/1000, color='red') circle_red3 = plt.Circle((0, 1), i/1000, color='red') circle_red4 = plt.Circle((1, 0), i/1000, color='red') ax.add_artist(circle_red1) ax.add_artist(circle_red2) ax.add_artist(circle_red3) ax.add_artist(circle_red4) return [circle_red1, circle_red2, circle_red3, circle_red4] ,但您还没有定义它。要定义 guild,请在上面添加:

guild

既然你现在已经定义了 guild = client.get_guild(GUILD ID) # Change 'GUILD ID' with your server id ,你不应该得到那个错误。

如果您尝试获取发送消息的公会,则应使用 guild 对象:

ctx

答案 1 :(得分:0)

您可以执行@IPSDSILVA 所做的操作来获取特定的公会,或者您可以通过执行 guild 来定义 ctx.guild.member_count 以获取运行该命令的服务器的成员计数。确保您有ctx 作为参数,如果你这样做。