检查wait_for_message是否仅返回数字

时间:2019-02-20 02:19:11

标签: python python-3.x discord discord.py

我下面的代码工作正常,但是如何使漫游器仅接受数字形式的用户消息,否则说“请仅添加数字”?

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_knit$set(root.dir = './Data')
library(ggplot2)
library(gganimate)
library(gapminder)
```

## slide 1
```{r, }
datain <- read.csv("table1.csv")
panim <- ggplot(datain, aes(x, y, frame = year)) + geom_point()
```

## Static plot view
```{r, }
panim
```

## Static plot add animate
```{r, }
panim2 <- panim + transition_time(year) + 
labs(title = "Year: {frame_time}")
```

## Activate animate 
```{r, }
animate(panim2)
```

2 个答案:

答案 0 :(得分:0)

您可以利用isdigit()并执行类似的操作

if reply.content.isdigit():
  await self.bot.send_message(ctx.message.channel, "{}".format(reply.content))
else:
  await self.bot.send_message(ctx.message.channel, "Please add only numbers")

答案 1 :(得分:0)

check中有一个wait_for_message()参数可以检查给定的消息是否适合用户定义的规则。

@commads.command(pass_context=True)
async def ping(self, ctx):
    message = await self.bot.send_message(ctx.message.channel, "Ask something")
    def is_number(msg):
        return msg.content.isdigit()
    reply = await self.bot.wait_for_message(author=ctx.message.author, channel=ctx.message.channel, check=is_number)
    await self.bot.send_message(ctx.message.channel, "{}".format(reply.content))

您还可以在is_number()中添加发送“请仅添加数字”的处理程序。