修复:添加不协调组件(bot)
我正在尝试获取按钮或下拉菜单,允许用户进行选择。但是,我一直无法让它工作,因为这两种方法最终都会给我带来组件问题
错误消息为: 第134行,单位为rps m=等待ctx.send( TypeError:send()获得意外的关键字参数“components”
我让pip安装了discord_组件并导入了它。我对错误消息的来源感到困惑
@bot.command(name = "rps")
async def rps(ctx):
ch1 = ["Rock","Scissors","Paper"]
comp = random.choice(ch1)
yet = discord.Embed(title = f"{ctx.author.display_name}'s RPS game", description = "You have yet to select anything")
win = discord.Embed(title = f"{ctx.author.display_name} Won!", descrption = "Congrats! You won.")
out = discord.Embed(title = f"{ctx.author.display_name} was too slow.", descrption = "Okay then you were just too slow for me. ")
lost = discord.Embed(title = f"{ctx.author.display_name} lost", descrption = "Aw darn. Unfortunatly you lost this one.")
tie = discord.Embed(title = f"{ctx.author.display_name} tied with the bot!", descrption = "Well thats interesting. It was a tie.")
m = await ctx.send(
embed=yet,
components=[Select(placeholder="Select 1", options=[SelectOption(label="Rock", value="Rock"), SelectOption(label="Paper", value="Paper"), SelectOption(label="Scissors", value="Scissors")])]
,
)
interaction = await bot.wait_for("select_option", check = lambda i: i.component[0].value == "A")
await interaction.respond(content = f"{interaction.component[0].label} selected!")
我导入的内容以及如何定义我的bot:
import os, csv, random, discord, asyncio, pandas, requests, json, traceback
from discord.ext import commands
from dotenv import load_dotenv
from discord_components import DiscordComponents, Button, Select, SelectOption
load_dotenv()
botToken = os.getenv("DiscBotToken")
我帮不了你,但我可以给你一个工作代码
然后选择Menu
嘿,我建议您使用官方API包装,而不是像
discord_components
或nextcord
等第三方库/依赖项。。。 如果您想查看discord.py v2(官方版本)的视图,请点击此处>https://github.com/Rapptz/discord.py/tree/45d498c1b76deaf3b394d17ccf56112fa691d160/examples/views如果您对代码有疑问或问题,请转到官方discord服务器>;discord.gg/dpy并在#测试频道中说?tester
,以访问v2问题频道相关问题 更多 >
编程相关推荐