擅长:python、mysql、java
<pre><code>@client.command()
async def button(ctx):
await ctx.channel.send(
"This is a button test",
components = [
Button(style=ButtonStyle.blue, label="Button 1")
]
)
res = await client.wait_for("button_click")
if res.channel == ctx.channel:
role = discord.utils.get(ctx.guild.roles, id = 853692936465940501)
await res.author.add_roles(role)
await res.respond(
type=4,
content=f"{res.component.label} has been clicked! This is button 1"
)
</code></pre>