Skip to content

Commit ada7763

Browse files
committed
1.Added bot.run() in simple_event. 2. Renamed 'fetch_component_message' to 'fetch_message' and fixed when use 'Context.fetch_message'
1 parent 4907b59 commit ada7763

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

discord_components/dpy_overrides.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,15 @@ async def send_override(context_or_channel, *args, **kwargs):
344344
return await send(channel, *args, **kwargs)
345345

346346

347-
async def fetch_component_message(self, id:int):
348-
channel = self
349-
data = await self._state.http.get_message(channel.id, id)
350-
return ComponentMessage(state=self._state, channel=channel, data=data)
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+
data = await context_or_channel._state.http.get_message(channel.id, id)
354+
return ComponentMessage(state=context_or_channel._state, channel=channel, data=data)
351355

352356

353357
Messageable.send = send_override
354-
Messageable.fetch_message = fetch_component_message
358+
Messageable.fetch_message = fetch_message

examples/simple_event.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ async def on_ready():
1717

1818
@bot.command()
1919
async def button(ctx):
20-
components = [Button(label="Button", custom_id="button1")]
21-
22-
await ctx.send("Buttons!", components=components)
20+
await ctx.send("Buttons!", components=[Button(label="Button", custom_id="button1")])
2321

2422

2523
@bot.event
@@ -29,21 +27,24 @@ async def on_button_click(interaction):
2927

3028
@bot.command()
3129
async def select(ctx):
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-
await ctx.send("Selects!",components=components)
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+
)
4443

4544

4645
@bot.event
4746
async def on_select_option(interaction):
4847
await interaction.respond(content=f"{interaction.values[0]} selected!")
4948

49+
50+
bot.run("your token")

0 commit comments

Comments
 (0)