我正在尝试创建一个命令来列出用户创建的所有邀请(包括每个链接的使用次数)并在聊天中返回总数。但是从我目前的代码中我得到的全部是:
<generator object Client.invites_from at 0x7f877ecc5780>
这是我的代码,看看我哪里出错:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
bot = discord.Client()
client = commands.Bot(command_prefix = "!")
@client.event
async def on_ready():
print("Bot Connected!")
@client.event
async def on_message(message):
if message.content == "!inv":
server = message.channel.server.id
invites = bot.invites_from(server)
await client.send_message(message.channel, invites)
client.run("TOKEN")
如果我尝试遍历返回的生成器,我会收到以下错误:
for i in invites:
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/discord/client.py", line 2693, in invites_from
data = yield from self.http.invites_from(server.id)
AttributeError: 'str' object has no attribute 'id'
非常感谢您提前提供任何帮助
答案 0 :(得分:0)
server = message.channel.server.id
中指出,您的问题似乎与id
中的这一行有关:
server = message.channel.server
回溯表明discord.py库正在尝试使用您传递它的服务器的invites_from
属性;目前,您正在传递ID,但您可能需要传递整个服务器对象。
IOW,请改为:
await
由于invites = await bot.invites_from(server)
是协程,因此您还需要Set Min Similarity 0.99
:
<table cellpadding="0" cellspacing="0" border="0" width="150" bgcolor="#000000" class="cta-black" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; padding: 0; border-collapse: collapse; mso-padding-alt: 0pt 0pt 0pt 0pt; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; border: 1px solid black; background: #000000;">
<tbody>
<tr>
<td class="separator" height="10" style="margin: 0; font-family: Arial; -webkit-text-size-adjust: none; color: #575757; clear: both; float: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; font-size: 5px !important; line-height: 5px !important;"> </td>
</tr>
<tr>
<td align="center" mc:edit="selection-1-cta" style="margin: 0; font-family: Arial; -webkit-text-size-adjust: none; color: #575757; clear: both; float: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;"><a href="#" target="_blank" style="border: none; color: #ffffff; text-decoration: none; outline: none !important; font-family: 'Montserrat', sans-serif; font-size: 13px; display: block;">VOIR LE PRODUIT</a></td>
</tr>
<tr>
<td class="separator" height="10" style="margin: 0; font-family: Arial; -webkit-text-size-adjust: none; color: #575757; clear: both; float: none; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; font-size: 5px !important; line-height: 5px !important;"> </td>
</tr>
</tbody>
</table>
答案 1 :(得分:0)
我设法解决了这个问题,那就是我的客户端和僵尸程序错误,所以机器人无法向API提供令牌,感谢所有人的帮助