我正在使用python来让我的机器人生成一个即时邀请。然而,我很难找到并创建即时邀请。这是我的代码:
from progress.bar import Bar # Only to show a loading bar, all imports are successful.
print("Loading...")
imports = [
'import os',
'import sys',
'import asyncio',
'import discord',
'import random',
'import functools',
'import time as tm',
'from discord.ext import commands',
'from discord.ext.commands import when_mentioned'
]
bar = Bar('', max=len(imports))
for i in range(0, len(imports)):
exec(str(imports[i]))
bar.next()
bar.finish()
BOT_PREFIX = "!"
BOT_TOKEN = 'token'
OWNER_ID = int("owner's user id for support")
class Stuff(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def create_invite(self, ctx):
"""- Create instant invite"""
link = await discord.abc.GuildChannel.create_invite(self, max_age='300')
await ctx.send("Here is an instant invite to your server: "+link)
当命令在不一致的情况下运行时,我会得到以下错误:
discord.ext.commands.errors.CommandInvokeError:命令引发了一个异常: AttributeError:‘AttributeError’对象没有属性'_state‘
如何正确地生成即时邀请?
发布于 2019-07-07 01:10:40
尝试使用邀请()
就像这样,
@commands.command()
async def create_invite(self, ctx):
"""Create instant invite"""
link = await ctx.channel.create_invite(max_age = 300)
await ctx.send("Here is an instant invite to your server: " + link)
发布于 2021-11-17 08:37:20
下面是一个示例;根据您的喜好格式化它:
@client.command(pass_context=True)
async def invite(ctx):
#Creating an invite link
link = await ctx.channel.create_invite(xkcd=True, max_age = 0, max_uses = 0)
#max_age = 0 The invite link will never exipre.
#max_uses = 0 Infinite users can join throught the link.
#-----------------------------------------------------#
#-------Embed Time-----#
em = discord.Embed(title=f"Join The {ctx.guild.name} Discord Server Now!", url=link, description=f"**{ctx.guild.member_count} Members** [**JOIN**]({link})\n\n**Invite link for {ctx.channel.mention} is created.**\nNumber of uses: **Infinite**\nLink Expiry Time: **Never**", color=0x303037)
#Embed Footer
em.set_footer(text=f"Made by </iFreakuYT>2.0#0908")
#Embed Thumbnail Image
em.set_thumbnail(url=ctx.guild.icon_url)
#Embed Author
em.set_author(name="INSTANT SERVER INVITE")
#-----------------------------------------#
await ctx.send(f"> {link}", embed=em)
输出:
https://stackoverflow.com/questions/56890485
复制相似问题