[英]Suggestion bot discord.py
我希望机器人使用 ✅ 和 ❎ 表情符号对自己的消息做出反应,以获得建议命令。 这是代码。 我该怎么做?
import discord
from discord.ext import commands
class suggestions(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(description = 'Add a suggestion for this community!')
async def suggest(self, ctx, *,suggestion):
await ctx.channel.purge(limit = 1)
channel = discord.utils.get(ctx.guild.text_channels, name = '💡│suggestions')
suggestEmbed = discord.Embed(colour = 0xFF0000)
suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
suggestEmbed.add_field(name = 'New suggestion!', value = f'{suggestion}')
await channel.send(embed=suggestEmbed)
def setup(bot):
bot.add_cog(suggestions(bot))
Messageable.send
返回一个discord.Message
object,然后你可以简单地.add_reaction
message = await ctx.send(embed=suggestEmbed)
await message.add_reaction('✅')
await message.add_reaction('❌')
注意:您需要 emoji 的 unicode 做出反应,得到它只是\:{emoji}:
参考:
我,我用这个:
@bot.command()
async def suggestion(ctx, *, content: str):
title, description= content.split('/')
embed = discord.Embed(title=title, description=description, color=0x00ff40)
channel = bot.get_channel(insert the channel ID here)
vote = await channel.send(embed=embed)
await vote.add_reaction("✅")
await vote.add_reaction("❌")
await ctx.send("your suggestion has been send")
您可以使用表情符号投票,尽情享受吧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.