如何解决:AttributeError: 'None Type'对象没有属性“invite”;不和谐.py?
我正在通过 API/Integromat 生成我的 Discord 公会频道的邀请代码。
"uses": 0,
"max_uses": 2,
"max_age": 604800,
"unique": true
接下来,我想知道使用哪个邀请将其与我发送此邮件的电子邮件地址配对。对于这个问题,我使用了以下代码:
#base on medium article:
#https://medium.com/@tonite/finding-the-invite-code-a-user-used-to-join-your-discord-server-using-discord-py-5e3734b8f21f
import os
import discord
from discord.ext import commands
import requests
from keep_alive import keep_alive
intents = discord.Intents.default().all()
intents.members = True
intents.invites = True
bot = commands.Bot(command_prefix="!", intents=intents)
client = discord.Client(intents=intents)
invites = {}
@client.event
async def on_ready():
for guild in client.guilds:
invites[guild.id] = await guild.invites()
def find_invite_by_code(invite_list, code):
for inv in invite_list:
if inv.code == code:
return inv
@client.event
async def on_member_join(member):
invites_before_join = invites[member.guild.id]
invites_after_join = await member.guild.invites()
for invite in invites_before_join:
if invite.uses < find_invite_by_code(invites_after_join, invite.code).uses:
await requests.post(f"https://WEBHOOK_URL?invite={invite.code}")
invites[member.guild.id] = invites_after_join
return
@client.event
async def on_member_remove(member):
invites[member.guild.id] = await member.guild.invites()
@client.event
async def on_message(message):
if message.content.startswith('!Hey'):
await client.wait_until_ready()
await message.channel.send(message.id)
return
keep_alive()
client.run(os.environ['BOT_TOKEN'])
当我尝试通过私有选项卡测试邀请时,在控制台中我输出:
AttributeError: 'None Type' object has no attribute 'code'
有时它也是 < strong>AttributeError:“None Type”对象没有属性“invite”
你知道我在哪里犯了错误吗? 也许这篇文章会给你一些启发:https://github.com/GregTCLTK/Discord-Invite-追踪器
I am generating invite codes to my discord guild channel through API/Integromat.
"uses": 0,
"max_uses": 2,
"max_age": 604800,
"unique": true
Nextly I want to know which invite was used to pair it with email adress for whom I sent this. For this problem I used this code:
#base on medium article:
#https://medium.com/@tonite/finding-the-invite-code-a-user-used-to-join-your-discord-server-using-discord-py-5e3734b8f21f
import os
import discord
from discord.ext import commands
import requests
from keep_alive import keep_alive
intents = discord.Intents.default().all()
intents.members = True
intents.invites = True
bot = commands.Bot(command_prefix="!", intents=intents)
client = discord.Client(intents=intents)
invites = {}
@client.event
async def on_ready():
for guild in client.guilds:
invites[guild.id] = await guild.invites()
def find_invite_by_code(invite_list, code):
for inv in invite_list:
if inv.code == code:
return inv
@client.event
async def on_member_join(member):
invites_before_join = invites[member.guild.id]
invites_after_join = await member.guild.invites()
for invite in invites_before_join:
if invite.uses < find_invite_by_code(invites_after_join, invite.code).uses:
await requests.post(f"https://WEBHOOK_URL?invite={invite.code}")
invites[member.guild.id] = invites_after_join
return
@client.event
async def on_member_remove(member):
invites[member.guild.id] = await member.guild.invites()
@client.event
async def on_message(message):
if message.content.startswith('!Hey'):
await client.wait_until_ready()
await message.channel.send(message.id)
return
keep_alive()
client.run(os.environ['BOT_TOKEN'])
When I am trying to test invite through private tab, in a console I have output:
AttributeError: 'None Type' object has no attribute 'code'
sometimes it's also AttributeError: 'None Type' object has no attribute 'invite'
Do you know where I am making a mistake??
Maybe this article give you some inspire: https://github.com/GregTCLTK/Discord-Invite-Tracker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新了 2 个更改:
这很有趣,因为有时我的 webhook 没有发送。我将在这里更新积压工作。
Updated 2 changes:
It's interesting because sometimes my webhook was send on the other hand not. I will update backlog here.
解决了。
创建的邀请仅在重新启动机器人后才会显示。
所以我需要创建 100 多个邀请,然后进行操作。
Solved.
Created invites will show only after restart bot.
So you I needed to create 100+ invites, and then manipulate.