为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 DIscord.py 取消邀请链接

如何使用 DIscord.py 取消邀请链接

慕森卡 2023-01-04 11:14:18
有没有一种方法可以使用 Discord.PY 创建邀请链接?我的代码如下/import discordfrom discord.ext import commandsimport pickleclient = commands.Bot("-")@client.eventasync def on_message(message):    message.content.lower()    if message.author == client.user:        return#checks if the bot it running.    if message.content.startswith("message"):        await message.channel.send("hello there")#tells the user where they are.    if message.content.startswith("whereami"):        await message.channel.send(f"You are in {message.guild.name} " + \            f"in the {message.channel.mention} channel!")    ##Creates Instant Invite    if message.content.startswith("createinvite"):        await create_invite(*, reason=None, **fields)        await message.channel.send("Here is an instant invite to your server: " + link)client.run('token')如果需要,让我知道您需要什么其他信息,如果我需要编辑它以使其更清楚。如果我需要导入其他任何东西,请告知我需要哪些库。
查看完整描述

2 回答

?
繁华开满天机

TA贡献1816条经验 获得超4个赞

@client.event

async def on_message(message):

    if message.content.lower().startswith("createinvite"):

        invite = await message.channel.create_invite()

        await message.channel.send(f"Here's your invite: {invite}")

并使用命令装饰器:


@client.command()

async def createinvite(ctx):

    invite = await ctx.channel.create_invite()

    await ctx.send(f"Here's your invite: {invite}")

参考:


查看完整回答
反对 回复 2023-01-04
?
GCT1015

TA贡献1827条经验 获得超4个赞

有没有办法创建一个,但只能使用一次?我有一个 on_message 事件:如果有人输入 xy,机器人就会踢他。在踢球之后我想给他发一条 xy 消息。(准备好了)然后我想给他发一个邀请



查看完整回答
反对 回复 2023-01-04
  • 2 回答
  • 0 关注
  • 139 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号