【发布时间】:2020-10-26 19:10:48
【问题描述】:
我正在开发一个为您提供成员的 Discord.py 机器人。以下是它的工作原理:
- 您输入
!find- 机器人将发送一个包含 2 或 3 个服务器的嵌入来加入 - 加入服务器获取金币
- 输入
!bal - 机器人回复并嵌入您的余额
- 输入
!buy [amount] [ad message] - 当人们输入
!find时,您的服务器会弹出一条广告消息
你是如何做到的,当你输入!buy [amount] [ad message]时,人们在输入!find时就会得到你的服务器?
这是 !buy 命令:
@client.command()
async def buy(ctx, price: int, *args):
link = await ctx.channel.create_invite(max_age = 0)
advertisement = ' '.join(args)
findlink = str(link)
findmessage = str(advertisement)
findguild = str(ctx.guild)
findoutput = findguild + '\n' + findlink + '\n' + findmessage
print(findoutput)
buyer = str(ctx.message.author.id)
if buyer not in amounts:
author = ctx.message.author
noacc = discord.Embed(
colour = discord.Colour.blue()
)
noacc.set_author(name=f'You do not have an account.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
noacc.add_field(name='Type "!register" to make an account.', value='\u200b', inline=False)
await ctx.send(embed=noacc)
elif amounts[buyer] < price:
author = ctx.message.author
notaff = discord.Embed(
colour = discord.Colour.blue()
)
notaff.set_author(name=f'You cannot afford this transaction.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
notaff.add_field(name='Join some more servers, then try again!', value='\u200b', inline=False)
await ctx.send(embed=notaff)
elif price < 5:
author = ctx.message.author
larger = discord.Embed(
colour = discord.Colour.blue()
)
larger.set_author(name=f'Amount must be 5 or larger.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
larger.add_field(name='Sorry!', value='\u200b', inline=False)
await ctx.send(embed=larger)
else:
author = ctx.message.author
buy = discord.Embed(
colour = discord.Colour.blue()
)
buy.set_author(name=f'Purchased {price} Members.', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
buy.add_field(name='This is what people will see when they type "!find"', value='\u200b', inline=False)
buy.add_field(name=f"**{ctx.guild}**", value=link, inline=False)
buy.add_field(name=f'{advertisement}', value='\u200b', inline=False)
await ctx.send(embed=buy)
amounts[buyer] -= price
这是 !find 命令:
@client.command(aliases=['f'])
async def find(ctx):
global advertisement, findlink, findguild, findmessage
useravatar = ctx.message.author.avatar
name = ctx.guild
link = await ctx.channel.create_invite(max_age = 0)
author = ctx.message.author
find = discord.Embed(
colour = discord.Colour.blue()
)
find.set_author(name='Find Servers', icon_url='https://cdn.discordapp.com/attachments/723566996817575948/723932425369026560/comrade.png')
find.add_field(name='Do you need help? Join our official help server:', value='\u200b', inline=False)
find.add_field(name="**iComrade [BOT]** (You won't get any coins from joining this server)", value='https://discord.gg/CMD3aaN', inline=False)
find.add_field(name=f'Hey {ctx.author.name}, join these servers to get **1 coin each**.', value='\u200b', inline=False)
find.add_field(name=f'**{name}**', value=f'\n{link}', inline=False)
await ctx.send(embed=find)
【问题讨论】:
标签: python discord.py discord.py-rewrite