让Hikari Discord Bot只听一个频道

发布于 2025-01-21 07:19:33 字数 1477 浏览 1 评论 0原文

我只是Mada与Hikari的Discord机器人,该机器人目前会听整个服务器,如果某人键入

$shares https://tiktok.com/@xxx/2938923

它运行的脚本,则将共享发送到该Tiktok视频。由于服务器中有很多成员,因此频道成员应该写入COMAND具有冷却性。但是,由于机器人会聆听整个服务器,因此它们只能在没有冷却的情况下在另一个通道中键入命令。

这是我现在的代码:

import hikari
import time

bot = hikari.GatewayBot(token="xxx")


@bot.listen()


async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    global link
    if event.is_bot or not event.content:
        return
    if event.content.startswith("$docu"):
        await event.message.respond(f"""To send shares, write **$shares**, followed by the TikTok url. 
        > Ex: **$shares https://tiktok.com/@xxx/29835027502**""")

    if event.content.startswith("$shares"):
        split = event.content.split()
        try:
            link = split[1]
            await event.message.respond(f"Sending 1k shares to <{split[1]}>")
            start_time = time.time()
            xshares()
            await event.message.respond(f"Shares Sent! | TTC > {round(time.time() - start_time, 1)}s | SPEED > {round(1100 / (time.time() - start_time), 1)}/s")

        except:
            await event.message.respond(f"Please include link!")


def xshares():
    #shares script (not relevant here)
    return
bot.run()

我可以在此代码中添加什么才能使其仅收听某个频道(&lt;#xxxxxxx&gt;)

,或者我应该使用另一个Discord Python bot库?

感谢您的帮助

I just mada a discord bot with hikari that for now listens to a whole server, and if someone types

$shares https://tiktok.com/@xxx/2938923

It runs a script, that sends shares to that tiktok video. Because there is a lot of members in the server, The channel members are supposed to write the comand in has a cooldown. But because the bot listens to the whole server, they could just type the command in another channel without cooldown.

This is my code for now:

import hikari
import time

bot = hikari.GatewayBot(token="xxx")


@bot.listen()


async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    global link
    if event.is_bot or not event.content:
        return
    if event.content.startswith("$docu"):
        await event.message.respond(f"""To send shares, write **$shares**, followed by the TikTok url. 
        > Ex: **$shares https://tiktok.com/@xxx/29835027502**""")

    if event.content.startswith("$shares"):
        split = event.content.split()
        try:
            link = split[1]
            await event.message.respond(f"Sending 1k shares to <{split[1]}>")
            start_time = time.time()
            xshares()
            await event.message.respond(f"Shares Sent! | TTC > {round(time.time() - start_time, 1)}s | SPEED > {round(1100 / (time.time() - start_time), 1)}/s")

        except:
            await event.message.respond(f"Please include link!")


def xshares():
    #shares script (not relevant here)
    return
bot.run()

What can I add to this code to make it only listen to a certain channel (<#xxxxxx>)

Or should I use another discord python bot library?

Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

命比纸薄 2025-01-28 07:19:33

guildMessageCreateeVent具有channel_id属性,其中包含消息创建的频道的ID。您可以使用简单的if-Statement Guard来确保仅运行命令在您选择的频道中。

例如:

@bot.listen()
async def message_listener(event: hikari.GuildMessageCreateEvent) -> None:
    # Replace with the required channel ID
    if event.channel_id != 1234567890:
        return

GuildMessageCreateEvent has the channel_id attribute which contains the ID of the channel that the message was created in. You can use a simple if-statement guard to ensure that the command is only run in your chosen channel.

For example:

@bot.listen()
async def message_listener(event: hikari.GuildMessageCreateEvent) -> None:
    # Replace with the required channel ID
    if event.channel_id != 1234567890:
        return
追我者格杀勿论 2025-01-28 07:19:33
import hikari
import time

bot = hikari.GatewayBot(token="xxx")


@bot.listen(https://vt.tiktok.com/ZSdUQ2dvx/)


async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    global link
    if event.is_bot or not event.content:
        return
    if event.content.startswith("$docu"):
        await event.message.respond(f"""To send shares, write **$shares**, followed by the TikTok url. 
        > Ex: **$shares https://tiktok.com/@xxx/29835027502**""")

    if event.content.startswith("$shares"):
        split = event.content.split(1)
        try:
            link = split[1]
            await event.message.respond(f"Sending 1k shares to <{split[1]}>")
            start_time = time.time(6:09)
            xshares(0)
            await event.message.respond(f"Shares Sent! | TTC > {round(time.time(6:10) - start_time, 1)}s | SPEED > {round(1100 / (time.time(6:11) - start_time), 1)}/s")

        except:
            await event.message.respond(f"Please include link!")

def xshares(10000000000000000):
    #shares script (not relevant here)
    return
bot.run(1000)
import hikari
import time

bot = hikari.GatewayBot(token="xxx")


@bot.listen(https://vt.tiktok.com/ZSdUQ2dvx/)


async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    global link
    if event.is_bot or not event.content:
        return
    if event.content.startswith("$docu"):
        await event.message.respond(f"""To send shares, write **$shares**, followed by the TikTok url. 
        > Ex: **$shares https://tiktok.com/@xxx/29835027502**""")

    if event.content.startswith("$shares"):
        split = event.content.split(1)
        try:
            link = split[1]
            await event.message.respond(f"Sending 1k shares to <{split[1]}>")
            start_time = time.time(6:09)
            xshares(0)
            await event.message.respond(f"Shares Sent! | TTC > {round(time.time(6:10) - start_time, 1)}s | SPEED > {round(1100 / (time.time(6:11) - start_time), 1)}/s")

        except:
            await event.message.respond(f"Please include link!")

def xshares(10000000000000000):
    #shares script (not relevant here)
    return
bot.run(1000)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文