python - 如何使用 DIScord.py 不和谐邀请链接
问题描述
有没有办法可以使用 Discord.PY 创建邀请链接?我的代码如下/
import discord
from discord.ext import commands
import pickle
client = commands.Bot("-")
@client.event
async 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')
如果需要,请告诉我您需要哪些其他信息,如果我需要对其进行编辑以使其更清晰。如果我需要导入其他任何东西,请告知我需要哪些库。
解决方案
@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}")
参考:
推荐阅读
- excel - 使用宏将公式粘贴到一系列单元格中
- c# - IBM MQ Windows 客户端 C# 连接到服务器失败并出现 2298 错误
- php - PHP strtotime 获取给定年份的最后一天
- c# - 我使用了太多的 if 语句
- javascript - chart.js 数据通过 API 根据选择动态形成
- mysql - 这种情况下怎么写SQL?
- python - 日期范围内的 xlsxwriter
- google-apps-script - 电子表格插件身份验证错误 - 文档所有者和活动用户不匹配
- angular - 如何正确地将带有 i18n 的 Angular 6 应用程序构建到带有 baseHref 的“语言环境目录”中?
- php - 根据邮政编码计算邮费