设置:我制作了一个机器人来与服务器上的用户进行交互。我增加的一个特点是马可波罗的游戏。当用户发送"Marco“时,机器人会以”POLO.“作为响应。
问题:当机器人用“POLO.”进行响应时,它与原始消息在同一个通道上响应。但是,我希望bot在服务器内的随机通道中作出响应,这会让用户寻找它。
我在网上搜索过答案,也在discord.py上搜索过,但是我一直找不到答案。然而,我对Python和编码完全陌生,所以很可能我只是遗漏了一些东西,或者它是不可能的,LOL。
这是马可波罗游戏的代码:
@client.event
async def on_message(message):
if m
我正在尝试创建一个不一致的帮助“日志”命令。
@client.command()
async def logs(ctx):
for channel in ctx.guild.channels:
if channel.name == "henry-logs":
await ctx.send("Henry Logs channel is already setup. If you have access to it, it should be available in the channel list")
else:
await ctx.s
这里我有一些考试代码:
for server in client.servers:
for channel in server.channels:
print(channel)
例如,输出是:
Text Channels
general
commands
Text Channels
main-channel
admin-channel
Text Channels
first-channel
我想发出命令!br,它将向每个服务器中的第一个信道发送消息。但我做不到,因为文本频道行也算作频道
我总是会犯这样的错误:
Cannot send messages
这是一个基本的想法-我不想要触发消息的作者,而是在触发消息的作者之前出现的消息。
希望举个例子,我的意思是:
初始消息:Author1: Foo
触发消息:Author2: That thing you said is cool
Bot的回应:Bot: @Author1 is cool!
显然,来自Author2的消息是什么触发了机器人,但是我如何让机器人找到前面消息的作者呢?到目前为止,我得到的是:
@commands.Cog.listener('on_message')
async def cool(self, message):
if me
我正在尝试制造一个机器人,它可以在每个服务器中发送消息到允许它发送消息的通道。
下面是代码:
@client.event
async def on_ready(): #executes when ran
print("Ready!")
while 1 == 1: #loops code below
for i in client.guilds: #going to all servers
for j in i.channels: #going to all channel in server
我需要清除10条消息作为默认和清除所有渠道,如果打印的-чисти все。它起了作用,但我的机器人现在不清除任何信息,我不知道我能做什么来修复它。请帮忙
cha=ctx.message.channel
author=ctx.message.author
if all=='все' or all=="всё":
amount=0
history=await cha.history(limit=9999999).flatten()
for i in history:
我正在编写一个机器人,需要在一个渠道中发送消息,用户已经激活它。我似乎找不到如何从消息中获取通道ID。 @bot.command(name="start", description="Starts for a channel")
async def start(ctx):
await ctx.send("Started")
#Get channel ID here and assign it to the var channel
@tasks.loop(seconds=2)
async def message()
如何在不使用数据库或列表的情况下获取用户在服务器中发送的所有消息?
也许有这样的方法:
messages = await message.guild.find_messages(author=message.author)
await message.channel.send(f"You sent {len(messages)} messages in this server")
我试图添加一个函数来检查用户在过去2天内发送的消息的数量,现在我正在遍历所有的通道历史并一次检查消息1,但是对于一个每天接收数千条消息的公会,这需要很长时间,有什么方法可以指定最大的回溯时间吗?
这是我的当前代码
# This is also inside of a cog
now = datetime.datetime.now()
joined_on = ctx.author.joined_at
delta = datetime.timedelta(joined_on, now)
if delta.days >= 2:
message = 0
for channel i
我一直试图运行一个创建文本通道的循环,然后直接向它发送多条消息。我想出了这样的代码:
@client.event
async def on_message(message):
msg = message.content
guild = message.guild
if msg.startswith("test") and message.author.id == admin:
await message.reply("valid", mention_author=True)
for i in range