discord py 按钮多次触发
discord py buttons triggered multiple times
所以我在 discord py 中制作了一个语音支持机器人,我遇到了关闭案例或报告滥用按钮的问题。
这是发送带有按钮的嵌入的代码(有效)
import discord
from discord.ext import commands
from discord_ui import Button, UI
@bot.event
async def on_voice_state_update(member, before, after):
try:
if after.channel.id == int("944642625351327784"):
if before.channel is None and after.channel is not None:
notifychannel = bot.get_channel(944642626055979059)
embed = discord.Embed(title="test")
notifyembed = await ui.components.send(notifychannel, embed=embed, components=[
Button("Close", f"close-{uservoicechannel.id}", "green", emoji="✅"),
Button("Abuse!", f"abuse-{uservoicechannel.id}", "red", emoji="️", new_line=False)
])
except:
pass
这是监听按钮点击的代码:
@bot.listen("on_button")
async def on_button(btn):
print(btn.component.custom_id)
一切正常,但是当打开 3 个频道并且有人点击一个按钮时,它会触发 3 次。
有没有办法解决这个问题,也许可以禁用带有自定义 ID 或某些 ID 的按钮?
致所有被困在同一个问题上的人:
使用 pycord 修复了它。
所以我在 discord py 中制作了一个语音支持机器人,我遇到了关闭案例或报告滥用按钮的问题。
这是发送带有按钮的嵌入的代码(有效)
import discord
from discord.ext import commands
from discord_ui import Button, UI
@bot.event
async def on_voice_state_update(member, before, after):
try:
if after.channel.id == int("944642625351327784"):
if before.channel is None and after.channel is not None:
notifychannel = bot.get_channel(944642626055979059)
embed = discord.Embed(title="test")
notifyembed = await ui.components.send(notifychannel, embed=embed, components=[
Button("Close", f"close-{uservoicechannel.id}", "green", emoji="✅"),
Button("Abuse!", f"abuse-{uservoicechannel.id}", "red", emoji="️", new_line=False)
])
except:
pass
这是监听按钮点击的代码:
@bot.listen("on_button")
async def on_button(btn):
print(btn.component.custom_id)
一切正常,但是当打开 3 个频道并且有人点击一个按钮时,它会触发 3 次。
有没有办法解决这个问题,也许可以禁用带有自定义 ID 或某些 ID 的按钮?
致所有被困在同一个问题上的人:
使用 pycord 修复了它。