让Hikari Discord Bot只听一个频道
我只是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
guildMessageCreateeVent
具有channel_id
属性,其中包含消息创建的频道的ID。您可以使用简单的if-Statement Guard来确保仅运行命令在您选择的频道中。例如:
GuildMessageCreateEvent
has thechannel_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: