Skip to content

Commit 6400ec3

Browse files
committed
Merge branch 'master' into 'master'
1. Fixed example and added new. 2.channel.fetch_message now return ComponentMessage See merge request discord.py-components/discord.py-components!14
2 parents 9ce5d6f + 03350c2 commit 6400ec3

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

discord_components/dpy_overrides.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,16 @@ async def send_override(context_or_channel, *args, **kwargs):
344344
return await send(channel, *args, **kwargs)
345345

346346

347+
async def fetch_message(context_or_channel, id:int):
348+
if isinstance(context_or_channel, Context):
349+
channel = context_or_channel.channel
350+
else:
351+
channel = context_or_channel
352+
353+
state = channel._state
354+
data = await state.http.get_message(channel.id, id)
355+
return ComponentMessage(state=state, channel=channel, data=data)
356+
357+
347358
Messageable.send = send_override
359+
Messageable.fetch_message = fetch_message

examples/example_cog.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ async def callback(interaction):
4545
],
4646
)
4747

48-
while True:
49-
interaction = await self.bot.wait_for("select_option")
50-
await interaction.respond(
51-
content=f"{','.join(map(lambda x: x.label, interaction.component))} selected!"
52-
)
5348

5449

5550
def setup(bot):

examples/simple_event.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from discord_components import Button, Select, SelectOption, ComponentsBot
2+
3+
4+
bot = ComponentsBot("!")
5+
"""
6+
or you can just override the methods yourself
7+
8+
bot = discord.ext.commands.Bot("!")
9+
DiscordComponents(bot)
10+
"""
11+
12+
13+
@bot.event
14+
async def on_ready():
15+
print(f"Logged in as {bot.user}!")
16+
17+
18+
@bot.command()
19+
async def button(ctx):
20+
await ctx.send("Buttons!", components=[Button(label="Button", custom_id="button1")])
21+
22+
23+
@bot.event
24+
async def on_button_click(interaction):
25+
await interaction.respond(content="Button Clicked")
26+
27+
28+
@bot.command()
29+
async def select(ctx):
30+
await ctx.send(
31+
"Selects!",
32+
components=[
33+
Select(
34+
placeholder="Select something!",
35+
options=[
36+
SelectOption(label="a", value="a"),
37+
SelectOption(label="b", value="b"),
38+
],
39+
custom_id="select1",
40+
)
41+
]
42+
)
43+
44+
45+
@bot.event
46+
async def on_select_option(interaction):
47+
await interaction.respond(content=f"{interaction.values[0]} selected!")
48+
49+
50+
bot.run("your token")

0 commit comments

Comments
 (0)