我听说ctx.typing()
存在,但我希望我的机器人在DM中显示指示器。到目前为止,这是我的代码:
@client.event
async def on_message(message):
await client.process_commands(message)
# i want the bot to display 'typing...' for 1 second
if message.guild is None and not message.author.bot:
with open('dmresponses.txt') as input_file:
long_list = [line.strip() for line in input_file]
await message.author.send(random.choice(long_list))
我该如何实现?
答案 0 :(得分:1)
这可以通过
<script>
import{Line} from 'vue-chartjs';
import {mapGetters,mapActions} from 'vuex';
export default {
extends:Line,
data: () => ({
chartdata: {
labels: ['January', 'February'],
datasets: [
{
label: 'Data One',
backgroundColor: '#f87979',
data: this.currentDeath
}
]
},
options: {
responsive: true,
maintainAspectRatio: false
}
}),
methods:{
...mapActions(["fetchData"]),
},
computed:{
...mapGetters(["currentDeath"])
},
created(){
this.fetchData()
},
mounted(){
const dates = this.
this.renderChart(this.chartData,this.options)
}
}
</script>
<style scoped>
</style>
上下文管理器来实现:
typing()
如果您想强调打字时长,可以使用@client.event
async def on_message(message):
await client.process_commands(message)
if message.guild is None and not message.author.bot:
async with message.channel.typing():
with open("dmresponses.txt") as input_file: # do stuff inside
long_list = [line.strip() for lin in input_file]
await message.author.send(random.choice(long_list)) # what to do after typing
来添加延迟:
asyncio.sleep()
参考:
Messageable.typing()
-可发消息的位置是您可以发送消息的地方(文本通道,DM,群聊等)。 import asyncio # required for the sleeping
async with message.channel.typing():
await asyncio.sleep(0.5)
# some stuff
await message.channel.send("Done!")
是message.channel
对象abc.Messageable
discord.TextChannel
asyncio.sleep()